{"record":{"id":"4dbb15420d7a9603","repo":"jackwener/OpenCLI","slug":"douyin-api-auth-permission-error-code-at-meth","errorCode":null,"errorMessage":"Douyin API auth/permission error ${code} at ${method} ${url}: ${msg}","messagePattern":"Douyin API auth/permission error (.+?) at (.+?) (.+?): (.+?)","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/douyin/_shared/browser-fetch.js","lineNumber":67,"sourceCode":"    }\n    catch (error) {\n        throw new CommandExecutionError(`Douyin API request failed (${method} ${url}): ${error instanceof Error ? error.message : String(error)}`);\n    }\n    if (result == null) {\n        throw new CommandExecutionError(\n            `Empty response from Douyin API (${method} ${url})`,\n            'The endpoint may have been retired or may now require signed parameters.',\n        );\n    }\n    if (Array.isArray(result) || typeof result !== 'object') {\n        throw new CommandExecutionError(`Malformed response from Douyin API (${method} ${url})`);\n    }\n    if (result && typeof result === 'object' && 'status_code' in result) {\n        const code = result.status_code;\n        if (code !== 0) {\n            const msg = result.status_msg ?? result.message ?? 'unknown error';\n            if (isAuthLikeError(code, msg)) {\n                throw new AuthRequiredError('creator.douyin.com', `Douyin API auth/permission error ${code} at ${method} ${url}: ${msg}`);\n            }\n            throw new CommandExecutionError(`Douyin API error ${code} at ${method} ${url}: ${msg}`);\n        }\n    }\n    return result;\n}\n","sourceCodeStart":49,"sourceCodeEnd":74,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/douyin/_shared/browser-fetch.js#L49-L74","documentation":"When the Douyin API responds with a non-zero status_code that looks like an auth/permission problem (per isAuthLikeError), browserFetch throws AuthRequiredError for creator.douyin.com. This signals the session's credentials are missing, expired, or lack permission for the endpoint.","triggerScenarios":"result.status_code !== 0 and isAuthLikeError(code, msg) is true — e.g. status codes/messages indicating not-logged-in, session expired, or insufficient permissions on creator.douyin.com APIs.","commonSituations":"Browser cookies expired overnight; running the CLI on a machine whose stored session was revoked; using an account without creator permissions; Douyin invalidating sessions after risk-control checks.","solutions":["Re-login to creator.douyin.com in the browser used by the tool and refresh the session/cookies.","Confirm the logged-in account has creator publishing permissions.","Retry after completing any captcha/risk-control challenge Douyin presented.","If persistent, clear stale cookie state and rebuild the authenticated session from scratch."],"exampleFix":"// before: retrying endlessly on auth error\nwhile (true) { await browserFetch(page, api); }\n// after: catch AuthRequiredError and force re-login\nimport { AuthRequiredError } from './_shared/errors.js';\ntry {\n  const data = await browserFetch(page, api);\n} catch (e) {\n  if (e instanceof AuthRequiredError) {\n    await reloginCreatorDouyin();\n    return browserFetch(page, api);\n  }\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"import { AuthRequiredError } from './_shared/errors.js';\ntry {\n  const data = await browserFetch(page, api);\n} catch (e) {\n  if (e instanceof AuthRequiredError) {\n    await relogin('creator.douyin.com');\n    return browserFetch(page, api); // single retry after re-auth\n  }\n  throw e;\n}","preventionTips":["Refresh creator.douyin.com cookies before long batch jobs","Check session validity with a lightweight authenticated endpoint first","Ensure the account has creator permissions for the APIs used","Handle captcha/risk-control prompts promptly to avoid session revocation"],"tags":["douyin","auth","session-expired","permissions"],"backgroundTag":"auth-required-session-expired","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}