jackwener/OpenCLI · error · AuthRequiredError
x.com
Error message
x.com
What it means
AuthRequiredError thrown when no username was given and the command tries to auto-detect the logged-in user by reading the AppTabBar_Profile_Link href from x.com/home, but the link is missing or yields no handle — meaning the session is not logged in (or the home page didn't render the nav).
Source
Thrown at clis/twitter/profile.js:101
columns: ['screen_name', 'name', 'bio', 'location', 'url', 'followers', 'following', 'tweets', 'likes', 'verified', 'created_at'],
func: async (page, kwargs) => {
const rawUsername = String(kwargs.username ?? '').trim();
let username = normalizeTwitterScreenName(rawUsername);
if (rawUsername && !username) {
throw new ArgumentError('twitter profile username must be a valid Twitter/X handle', 'Example: opencli twitter profile @jack');
}
// If no username, detect the logged-in user.
// Bridge wraps primitive page.evaluate returns as { session, data:<value> };
// unwrap so the href string is usable downstream.
if (!username) {
await page.goto('https://x.com/home');
await page.wait({ selector: '[data-testid="primaryColumn"]' });
const href = unwrapBrowserResult(await page.evaluate(`() => {
const link = document.querySelector('a[data-testid="AppTabBar_Profile_Link"]');
return link ? link.getAttribute('href') : null;
}`));
if (!href || typeof href !== 'string')
throw new AuthRequiredError('x.com', 'Could not detect logged-in user. Are you logged in?');
username = normalizeTwitterScreenName(href);
if (!username)
throw new AuthRequiredError('x.com', 'Could not detect logged-in user. Are you logged in?');
}
// Navigate directly to the user's profile page (gives us cookie context)
await page.goto(`https://x.com/${username}`);
await page.wait(3);
// Read CSRF token directly from the cookie store via CDP — zero page.evaluate round-trip
const cookies = await page.getCookies({ url: 'https://x.com' });
const ct0 = cookies.find((c) => c.name === 'ct0')?.value || null;
if (!ct0)
throw new AuthRequiredError('x.com', 'Not logged into x.com (no ct0 cookie)');
const resolvedOperation = await resolveTwitterOperationMetadata(page, 'UserByScreenName', USER_BY_SCREEN_NAME_OPERATION);
const operation = { queryId: resolvedOperation.queryId, features: resolvedOperation.features };
const rawResult = unwrapBrowserResult(await page.evaluate(`
async () => {
const screenName = ${JSON.stringify(username)};
const ct0 = ${JSON.stringify(ct0)};View on GitHub (pinned to 49907e53dc)
Solutions
- Log in: run `opencli login` and complete authentication in the browser
- Retry the command after confirming x.com shows the logged-in home timeline
- Pass the username explicitly (`opencli twitter profile @handle`) to skip auto-detection entirely
- If logged in but the error persists, X likely changed the AppTabBar_Profile_Link selector; report/update it
Example fix
// before opencli twitter profile # relies on logged-in detection // after opencli twitter profile @myhandle # explicit, no auth detection needed
Defensive patterns
Strategy: try-catch
Validate before calling
// pre-flight: confirm the session is logged in before profile auto-detection
await page.goto('https://x.com/home');
const loggedIn = await page.evaluate(
"() => !!document.querySelector('a[data-testid=\"AppTabBar_Profile_Link\"]')"
);
if (!loggedIn) throw new Error('run `opencli login` first'); Try / catch
try {
profile = await opencli('twitter profile'); // auto-detect
} catch (e) {
if (e.name === 'AuthRequiredError') {
await opencli('login');
profile = await opencli('twitter profile');
} else throw e;
} Prevention
- Run `opencli login` before unattended runs
- Pass the username explicitly to skip logged-in detection
- Periodically re-authenticate; X sessions expire
- After X frontend deploys, verify the AppTabBar_Profile_Link selector still exists
When it happens
Trigger: Calling `opencli twitter profile` without a username while the browser session's x.com/home lacks a[data-testid="AppTabBar_Profile_Link"] (logged out, login wall, or X renamed the nav link), or the href doesn't normalize to a handle.
Common situations: Session cookies expired; `opencli login` never run or browser profile reset; X changed the AppTabBar testid after a frontend deploy; x.com/home redirected to the logged-out landing page.
Related errors
- 未获取到课程列表
- Chaoxing session cookies missing
- ChatGPT project requires a logged-in ChatGPT session.
- Claude sessionKey cookie missing
- Claude session incomplete — ajs_user_id cookie missing
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/ec2bc6dc14170481.
Report an issue: GitHub.