{"record":{"id":"36608926840a4512","repo":"jackwener/OpenCLI","slug":"www-youtube-com-366089","errorCode":null,"errorMessage":"www.youtube.com","messagePattern":"www\\.youtube\\.com","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"critical","filePath":"clis/youtube/unsubscribe.js","lineNumber":69,"sourceCode":"            'Content-Type': 'application/json',\n            'Authorization': authHash,\n            'X-Origin': 'https://www.youtube.com',\n          },\n          body: JSON.stringify({ context, channelIds: [channelId] }),\n        });\n\n        if (resp.status === 401 || resp.status === 403) return { error: 'auth', message: 'Not logged in' };\n        if (!resp.ok) {\n          const body = await resp.json().catch(() => ({}));\n          const errStatus = body?.error?.status || '';\n          if (errStatus === 'UNAUTHENTICATED') return { error: 'auth', message: 'Not logged in' };\n          return { error: 'http', message: 'HTTP ' + resp.status + (errStatus ? ' ' + errStatus : '') };\n        }\n        return { ok: true, channelId };\n      })()\n    `);\n        if (result?.error === 'auth') {\n            throw new AuthRequiredError('www.youtube.com');\n        }\n        if (result?.error) {\n            throw new CommandExecutionError(result.message || 'Failed to unsubscribe');\n        }\n        return [{ status: 'success', message: 'Unsubscribed from: ' + (result.channelId || channelInput) }];\n    },\n});\n","sourceCodeStart":51,"sourceCodeEnd":77,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/youtube/unsubscribe.js#L51-L77","documentation":"AuthRequiredError re-thrown after the in-page unsubscribe API call reports error === 'auth'. A SAPISID cookie existed, but YouTube's subscribe/unsubscribe internal endpoint responded as unauthenticated (e.g. HTTP 401), so the library surfaces AuthRequiredError for www.youtube.com. This indicates the stored session is no longer server-side valid.","triggerScenarios":"The page.evaluate payload returns { error: 'auth' } — the /youtubei/v1/subscription/unsubscribe call returns 401 or another auth-required status despite the SAPISID cookie being present.","commonSituations":"Expired/stale SAPISID from a revoked Google session; account security changes invalidating cookies; consent or verification walls on the account; YouTube changing auth expectations for internal APIs.","solutions":["Re-login to www.youtube.com in the automation profile to mint fresh session cookies, then retry.","Delete stale YouTube cookies and sign in again so SAPISID matches a live session.","Confirm the page-side request sends a correct SAPISIDHASH Authorization header with the current origin and SAPISID.","Update the library/tooling if YouTube altered its internal unsubscribe endpoint auth behavior."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"const sapisid = await readYoutubeSapisid(page);\nif (!sapisid) throw new Error('YouTube session invalid — re-login required');","typeGuard":null,"tryCatchPattern":"try {\n  await unsubscribe({ channel });\n} catch (e) {\n  if (e.name === 'AuthRequiredError') {\n    await refreshYoutubeSession(page);\n    return unsubscribe({ channel });\n  }\n  throw e;\n}","preventionTips":["Re-login when internal API calls return 401 even with a SAPISID present — the session is server-side stale.","Periodically validate the session with a lightweight authenticated API call before batch operations.","Keep Authorization (SAPISIDHASH) header generation current with ytcfg and origin.","Handle account security/consent walls that can invalidate subscriptions API access."],"tags":["auth","youtube","session-expired","api-401"],"backgroundTag":"auth-required","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}