{"record":{"id":"976af3bf474e95e5","repo":"jackwener/OpenCLI","slug":"twitter-userbyscreenname-returned-graphql-errors","errorCode":null,"errorMessage":"Twitter UserByScreenName returned GraphQL errors: ${JSON.stringify(normalizedUserLookup.errors).slice(0, 200)}","messagePattern":"Twitter UserByScreenName returned GraphQL errors: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/twitter/download.js","lineNumber":376,"sourceCode":"        'X-Csrf-Token': ct0,\n        'X-Twitter-Auth-Type': 'OAuth2Session',\n        'X-Twitter-Active-User': 'yes',\n    });\n\n    const ubsUrl = buildUserByScreenNameUrl(userByScreenNameOperation, username);\n    const userLookup = requireFetchPayload(await page.evaluate(`async () => {\n      try {\n        const resp = await fetch(\"${ubsUrl}\", { headers: ${headers}, credentials: 'include' });\n        if (!resp.ok) return { ok: false, status: resp.status };\n        const payload = await resp.json();\n        return { ok: true, payload };\n      } catch (err) {\n        return { ok: false, error: err?.message ?? String(err) };\n      }\n    }`));\n    const normalizedUserLookup = normalizeTwitterGraphqlPayload(userLookup);\n    if (Array.isArray(normalizedUserLookup?.errors) && normalizedUserLookup.errors.length > 0) {\n        throw new CommandExecutionError(`Twitter UserByScreenName returned GraphQL errors: ${JSON.stringify(normalizedUserLookup.errors).slice(0, 200)}`);\n    }\n    const userId = normalizedUserLookup?.data?.user?.result?.rest_id;\n    if (!userId) throw new EmptyResultError(`twitter download @${username}`, `Could not resolve @${username}`);\n\n    const seen = new Set();\n    const all = [];\n    let cursor = null;\n    let hasMorePages = false;\n    for (let i = 0; i < MAX_PAGINATION_PAGES && all.length < limit; i++) {\n        const fetchCount = nextUserMediaFetchCount(limit, all.length);\n        if (fetchCount === 0) break;\n        const url = buildUserMediaUrl(userMediaOperation, userId, fetchCount, cursor);\n        const data = normalizeTwitterGraphqlPayload(requireFetchPayload(await page.evaluate(`async () => {\n        try {\n          const r = await fetch(\"${url}\", { headers: ${headers}, credentials: 'include' });\n          if (!r.ok) return { ok: false, status: r.status };\n          return { ok: true, payload: await r.json() };\n        } catch (err) {","sourceCodeStart":358,"sourceCodeEnd":394,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/twitter/download.js#L358-L394","documentation":"The UserByScreenName GraphQL lookup can succeed at HTTP level but return a payload containing an `errors` array (Twitter's GraphQL error channel). The code normalizes the payload and, if errors exist, throws a CommandExecutionError including up to 200 characters of the serialized errors for diagnosis.","triggerScenarios":"Fetching the UserByScreenName endpoint when the account is suspended or doesn't exist, the queryId/operation metadata is stale (x.com deploy changed it), the CSRF token is invalid, or Twitter rate-limits/forbids the request.","commonSituations":"Typo in the username (handle not found); account suspended/deactivated; x.com shipped a new GraphQL operation hash making the cached metadata rejected; too many rapid requests triggering server-side errors.","solutions":["Verify the username exists and is not suspended by visiting https://x.com/<username>","Re-run after a delay to rule out transient rate limiting","Refresh/update the CLI so resolveTwitterOperationMetadata picks up current UserByScreenName operation metadata","Re-login to the browser session to ensure the CSRF token is valid"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"const res = await fetch(url, { headers, credentials: 'include' });\nif (!res.ok) throw new Error(`UserByScreenName HTTP ${res.status}`);","typeGuard":"const hasGraphqlErrors = (payload) => Array.isArray(payload?.errors) && payload.errors.length > 0;","tryCatchPattern":"try {\n  await cmd();\n} catch (err) {\n  if (err.name === 'CommandExecutionError' && err.message.includes('GraphQL errors')) {\n    // inspect err.message for error code (e.g. 144 user not found) and back off/retry\n  }\n}","preventionTips":["Confirm the target handle exists and is not suspended before running","Back off on rate limits; space out repeated invocations","Keep operation metadata (queryId) fresh via CLI updates"],"tags":["graphql","api-error","twitter"],"backgroundTag":"graphql-errors-response","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}