{"record":{"id":"c5fab628f6e40b44","repo":"jackwener/OpenCLI","slug":"tiktok-studio-item-list-requires-login-statusms-c5fab6","errorCode":null,"errorMessage":"TikTok Studio item_list requires login: ${statusMsg}","messagePattern":"TikTok Studio item_list requires login: (.+?)","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/tiktok/creator-videos.js","lineNumber":126,"sourceCode":"function unwrapPayload(data) {\n    if (!data || typeof data !== 'object') {\n        throw new CommandExecutionError('TikTok Studio item_list returned an empty response');\n    }\n    return data.data && typeof data.data === 'object' ? data.data : data;\n}\n\nfunction assertApiSuccess(data) {\n    const statusCode = data.status_code ?? data.statusCode;\n    const statusMsg = String(data.status_msg ?? data.statusMsg ?? '').trim();\n    if (statusCode !== undefined && Number(statusCode) !== 0) {\n        if (looksAuthFailure(statusMsg)) {\n            throw new AuthRequiredError('www.tiktok.com', `TikTok Studio item_list requires login: ${statusMsg || statusCode}`);\n        }\n        throw new CommandExecutionError(`TikTok Studio item_list failed: ${statusMsg || statusCode}`);\n    }\n    if (statusMsg && !/^(success|ok)$/i.test(statusMsg)) {\n        if (looksAuthFailure(statusMsg)) {\n            throw new AuthRequiredError('www.tiktok.com', `TikTok Studio item_list requires login: ${statusMsg}`);\n        }\n        throw new CommandExecutionError(`TikTok Studio item_list failed: ${statusMsg}`);\n    }\n}\n\nfunction normalizeNumber(value) {\n    const n = Number(value);\n    return Number.isFinite(n) ? n : 0;\n}\n\nfunction formatDate(value) {\n    const seconds = Number(value);\n    if (!Number.isFinite(seconds) || seconds <= 0) return '';\n    return new Date(seconds * 1000).toLocaleString('zh-CN', {\n        timeZone: 'Asia/Shanghai',\n        hour12: false,\n    });\n}","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/tiktok/creator-videos.js#L108-L144","documentation":"A second auth check in assertApiSuccess: even when status_code is 0 or absent, if a non-success status_msg matches the auth-failure regex, the library raises AuthRequiredError for www.tiktok.com. This catches TikTok responses that signal login problems via the message text alone.","triggerScenarios":"item_list returns success-ish statusCode but status_msg like 'not logged in' or 'unauthorized user' — e.g. stale session cookies accepted at transport level but rejected logically.","commonSituations":"Half-expired sessions; cookies for the wrong domain; account logged out elsewhere mid-run; running the CLI in CI where cookies were exported from a machine that has since logged out.","solutions":["Re-authenticate with the CLI's TikTok login flow and retry.","Re-export fresh cookies from a logged-in browser session.","Confirm no other device/process is invalidating the session concurrently."],"exampleFix":"// before\nconst page = await fetchCreatorVideosPage(...); // AuthRequiredError\n// after\nif (!(await tiktokSessionValid())) {\n  await tiktokLogin();\n}\nconst page = await fetchCreatorVideosPage(...);","handlingStrategy":"try-catch","validationCode":"const cookies = await loadCookies('www.tiktok.com');\nif (!cookies || cookies.length === 0) {\n  throw new Error('No TikTok cookies found; run login first');\n}","typeGuard":null,"tryCatchPattern":"try {\n  const videos = await listCreatorVideos(opts);\n} catch (e) {\n  if (String(e.message).includes('requires login')) {\n    await tiktokLogin('www.tiktok.com');\n    return listCreatorVideos(opts);\n  }\n  throw e;\n}","preventionTips":["Re-export cookies from a freshly logged-in browser for CI runs.","Detect session staleness with a cheap authenticated endpoint before batch jobs.","Handle AuthRequiredError with an automatic re-login path.","Keep one canonical login session to avoid concurrent logouts."],"tags":["authentication","tiktok","session-expired","cookies"],"backgroundTag":"auth-required","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}