{"record":{"id":"f38bc7c00fcb7944","repo":"jackwener/OpenCLI","slug":"www-youtube-com-f38bc7","errorCode":null,"errorMessage":"www.youtube.com","messagePattern":"www\\.youtube\\.com","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/youtube/like.js","lineNumber":25,"sourceCode":"\ncli({\n    site: 'youtube',\n    name: 'like',\n    access: 'write',\n    description: 'Like a YouTube video',\n    domain: 'www.youtube.com',\n    strategy: Strategy.COOKIE,\n    args: [\n        { name: 'url', required: true, positional: true, help: 'YouTube video URL or video ID' },\n    ],\n    columns: ['status', 'message'],\n    func: async (page, kwargs) => {\n        const videoId = parseVideoId(String(kwargs.url));\n        await prepareYoutubeApiPage(page);\n        // Read SAPISID directly from the cookie store via CDP — zero document.cookie round-trip\n        const sapisid = await readYoutubeSapisid(page);\n        if (!sapisid)\n            throw new AuthRequiredError('www.youtube.com', 'Not logged in (SAPISID cookie missing)');\n        const result = await page.evaluate(`\n      (async () => {\n        ${SAPISID_HASH_FN}\n\n        const cfg = window.ytcfg?.data_ || {};\n        const apiKey = cfg.INNERTUBE_API_KEY;\n        const context = cfg.INNERTUBE_CONTEXT;\n        if (!apiKey || !context) return { error: 'config', message: 'YouTube config not found' };\n\n        const authHash = await getSapisidHash(${JSON.stringify(sapisid)}, 'https://www.youtube.com');\n        if (!authHash) return { error: 'auth', message: 'Not logged in (SAPISID cookie missing)' };\n\n        const resp = await fetch('/youtubei/v1/like/like?key=' + apiKey + '&prettyPrint=false', {\n          method: 'POST',\n          credentials: 'include',\n          headers: {\n            'Content-Type': 'application/json',\n            'Authorization': authHash,","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/youtube/like.js#L7-L43","documentation":"AuthRequiredError thrown before any API call is made because readYoutubeSapisid found no SAPISID cookie for www.youtube.com. The like command uses SAPISIDHASH authorization, which is only available when the browser profile is logged into YouTube. The library throws it to force re-authentication instead of sending an unauthenticated request that YouTube would reject.","triggerScenarios":"Calling `youtube like <url>` while the CLI's browser profile has no logged-in Google/YouTube session (SAPISID cookie absent from the cookie store), or cookies were recently cleared/expired.","commonSituations":"Freshly provisioned or headless CI profiles with no YouTube login, Google session expired after ~2 weeks, using the wrong profile directory, or a account region/consent flow that never set SAPISID.","solutions":["Log into www.youtube.com in the CLI's browser profile, then retry","If already logged in, verify the correct profile directory is being used","Clear Google cookies and log in again to force fresh SAPISID issuance"],"exampleFix":"// before\nopencli youtube like https://youtu.be/dQw4w9WgXcQ   // AuthRequiredError\n// after\nopencli auth login youtube   # or open the profile browser, log in, then retry","handlingStrategy":"validation","validationCode":"// check the profile can authenticate before calling like\nconst cookies = await profile.cookies('https://www.youtube.com');\nif (!cookies.some(c => c.name === 'SAPISID')) {\n  throw new Error('YouTube not logged in: run `opencli auth login youtube` first');\n}","typeGuard":"const hasSapisid = (cookies) => Array.isArray(cookies) && cookies.some(c => c.name === 'SAPISID' && c.domain?.includes('youtube.com'));","tryCatchPattern":"try {\n  await run('youtube like', [url]);\n} catch (e) {\n  if (/not logged in|SAPISID/i.test(e.message)) {\n    console.error('Auth required: log into youtube.com in the CLI profile, then retry');\n  } else throw e;\n}","preventionTips":["Log into youtube.com once in the dedicated CLI profile","Refresh the Google session before long-running automations","Never clear Google cookies without re-authenticating afterwards","Check for SAPISID cookie availability before batch like operations"],"tags":["youtube","auth","sapisid","cookies"],"backgroundTag":"youtube-not-logged-in","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}