From 4787b2c726086f1afb93295e968dd209712e6557 Mon Sep 17 00:00:00 2001 From: GoDotDotDot Date: Wed, 24 Apr 2024 19:17:18 +0800 Subject: [PATCH] fix(route): tweet detail not work (#15355) --- lib/routes/twitter/api/web-api/constants.ts | 30 +++++++++++++++++++++ lib/routes/twitter/api/web-api/utils.ts | 2 +- lib/routes/twitter/tweet.ts | 11 +++++++- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/lib/routes/twitter/api/web-api/constants.ts b/lib/routes/twitter/api/web-api/constants.ts index 5dab4c0ae..c84e3c835 100644 --- a/lib/routes/twitter/api/web-api/constants.ts +++ b/lib/routes/twitter/api/web-api/constants.ts @@ -10,6 +10,7 @@ const graphQLEndpointsPlain = [ '/graphql/tD8zKvQzwY3kdx5yz6YmOw/UserByRestId', '/graphql/flaR-PUMshxFWZWPNpq4zA/SearchTimeline', '/graphql/TOTgqavWmxywKv5IbMMK1w/ListLatestTweetsTimeline', + '/graphql/zJvfJs3gSbrVhC0MKjt_OQ/TweetDetail', ]; const gqlMap = Object.fromEntries(graphQLEndpointsPlain.map((endpoint) => [endpoint.split('/')[3].replace(/V2$|Query$|QueryV2$/, ''), endpoint])); @@ -49,6 +50,34 @@ const gqlFeatureFeed = { longform_notetweets_inline_media_enabled: true, responsive_web_enhance_cards_enabled: false, }; + +const TweetDetailFeatures = { + rweb_tipjar_consumption_enabled: true, + responsive_web_graphql_exclude_directive_enabled: true, + verified_phone_label_enabled: false, + creator_subscriptions_tweet_preview_api_enabled: true, + responsive_web_graphql_timeline_navigation_enabled: true, + responsive_web_graphql_skip_user_profile_image_extensions_enabled: false, + communities_web_enable_tweet_community_results_fetch: true, + c9s_tweet_anatomy_moderator_badge_enabled: true, + articles_preview_enabled: false, + tweetypie_unmention_optimization_enabled: true, + responsive_web_edit_tweet_api_enabled: true, + graphql_is_translatable_rweb_tweet_is_translatable_enabled: true, + view_counts_everywhere_api_enabled: true, + longform_notetweets_consumption_enabled: true, + responsive_web_twitter_article_tweet_consumption_enabled: true, + tweet_awards_web_tipping_enabled: false, + creator_subscriptions_quote_tweet_preview_enabled: false, + freedom_of_speech_not_reach_fetch_enabled: true, + standardized_nudges_misinfo: true, + tweet_with_visibility_results_prefer_gql_limited_actions_policy_enabled: true, + tweet_with_visibility_results_prefer_gql_media_interstitial_enabled: true, + rweb_video_timestamps_enabled: true, + longform_notetweets_rich_text_read_enabled: true, + longform_notetweets_inline_media_enabled: true, + responsive_web_enhance_cards_enabled: false, +}; const gqlFeatures = { UserByScreenName: gqlFeatureUser, UserByRestId: gqlFeatureUser, @@ -58,6 +87,7 @@ const gqlFeatures = { SearchTimeline: gqlFeatureFeed, ListLatestTweetsTimeline: gqlFeatureFeed, HomeTimeline: gqlFeatureFeed, + TweetDetail: TweetDetailFeatures, }; const timelineParams = { diff --git a/lib/routes/twitter/api/web-api/utils.ts b/lib/routes/twitter/api/web-api/utils.ts index b76647de1..4477684e9 100644 --- a/lib/routes/twitter/api/web-api/utils.ts +++ b/lib/routes/twitter/api/web-api/utils.ts @@ -55,7 +55,6 @@ export const paginationTweets = async (endpoint: string, userId: number | undefi }), features: JSON.stringify(gqlFeatures[endpoint]), }); - let instructions; if (path) { instructions = data; @@ -121,5 +120,6 @@ export function gatherLegacyFromData(entries: any[], filterNested?: string[], us } } } + return tweets; } diff --git a/lib/routes/twitter/tweet.ts b/lib/routes/twitter/tweet.ts index c5404b751..1883869ce 100644 --- a/lib/routes/twitter/tweet.ts +++ b/lib/routes/twitter/tweet.ts @@ -39,7 +39,16 @@ async function handler(ctx) { const status = ctx.req.param('status'); const routeParams = new URLSearchParams(ctx.req.param('original')); const original = fallback(undefined, queryToBoolean(routeParams.get('original')), false); - const params = { focalTweetId: status }; + const params = { + focalTweetId: status, + with_rux_injections: false, + includePromotedContent: true, + withCommunity: true, + withQuickPromoteEligibilityTweetFields: true, + withBirdwatchNotes: true, + withVoice: true, + withV2Timeline: true, + }; await api.init(); const userInfo = await api.getUser(id); const data = await api.getUserTweet(id, params);