Skip to content

fix(twitter): use dynamic features for profile command - #2274

Open
BernardGeorge wants to merge 1 commit into
jackwener:mainfrom
BernardGeorge:fix/twitter-profile-dynamic-features
Open

fix(twitter): use dynamic features for profile command#2274
BernardGeorge wants to merge 1 commit into
jackwener:mainfrom
BernardGeorge:fix/twitter-profile-dynamic-features

Conversation

@BernardGeorge

Copy link
Copy Markdown

Summary

Fixes #2273

opencli twitter profile returns 0 for followers/following/tweets/likes and empty for bio because it uses hardcoded features flags that Twitter no longer accepts.

Problem

clis/twitter/profile.js hardcodes 13 feature flags for the UserByScreenName GraphQL API. When these flags are outdated, Twitter returns a truncated response missing relationship_counts, legacy, profile_bio, tweet_counts, and action_counts — so all numeric fields default to 0 and bio to empty string.

Meanwhile, shared.js already provides resolveTwitterOperationMetadata() which returns both the correct queryId AND the current features (fetched from fa0311/twitter-openapi). But profile.js only calls resolveTwitterQueryId() which discards the features.

Fix

3 changes in clis/twitter/profile.js:

  1. Import resolveTwitterOperationMetadata from shared.js
  2. Replace resolveTwitterQueryId() with resolveTwitterOperationMetadata() to get both queryId and features
  3. Replace the hardcoded features block with the dynamically-resolved features, injected into page.evaluate via template literal
- import { ..., resolveTwitterQueryId, unwrapBrowserResult } from './shared.js';
+ import { ..., resolveTwitterQueryId, resolveTwitterOperationMetadata, unwrapBrowserResult } from './shared.js';

- const queryId = await resolveTwitterQueryId(page, 'UserByScreenName', USER_BY_SCREEN_NAME_QUERY_ID);
+ const __op = await resolveTwitterOperationMetadata(page, 'UserByScreenName', USER_BY_SCREEN_NAME_QUERY_ID);
+ const queryId = __op.queryId;
+ const __featuresJson = JSON.stringify(__op.features || {});

- const features = JSON.stringify({
-   hidden_profile_subscriptions_enabled: true,
-   // ... 13 hardcoded flags
- });
+ const features = ${JSON.stringify(__featuresJson)};

Verification

Before (hardcoded features):

{"screen_name": "elonmusk", "name": "Elon Musk", "bio": "", "followers": 0, "tweets": 0, "likes": 0}

After (dynamic features):

{"screen_name": "elonmusk", "name": "Elon Musk", "bio": "https://t.co/ZdBx5WABYx", "followers": 241243979, "following": 1386, "tweets": 106924, "likes": 243349}

Tested with OPENCLI_HEADFUL=1 OPENCLI_KEEP_TAB=true opencli twitter profile @elonmusk --format json.

The profile command hardcoded 13 feature flags that became outdated.
When these flags don't match what Twitter expects, the UserByScreenName
GraphQL API returns a truncated response missing relationship_counts,
legacy, profile_bio, tweet_counts, and action_counts — causing
followers/following/tweets/likes to return 0 and bio to return empty.

Fix: use resolveTwitterOperationMetadata() (already available in shared.js)
to get both queryId AND the correct dynamic features from
fa0311/twitter-openapi, instead of only using resolveTwitterQueryId()
which discards the features.

Verified: opencli twitter profile @ElonMusk now returns
followers=241243979, bio='https://t.co/ZdBx5WABYx', tweets=106924
instead of all zeros/empty.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(twitter): profile returns 0/empty for followers, bio, tweets, likes due to hardcoded features

1 participant