Skip to content

Commit

Permalink
fix: usually get fetching tweets to work again
Browse files Browse the repository at this point in the history
  • Loading branch information
karashiiro committed Aug 26, 2023
1 parent 3de6b87 commit c0de042
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/timeline-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export interface TimelineInstruction {

export interface TimelineV2 {
data?: {
user_result?: {
user?: {
result?: {
timeline_response?: {
timeline?: {
Expand Down Expand Up @@ -271,8 +271,8 @@ export function parseTimelineTweetsV2(
let cursor: string | undefined;
const tweets: Tweet[] = [];
const instructions =
timeline.data?.user_result?.result?.timeline_response?.timeline
?.instructions ?? [];
timeline.data?.user?.result?.timeline_response?.timeline?.instructions ??
[];
for (const instruction of instructions) {
const entries = instruction.entries ?? [];

Expand Down
36 changes: 32 additions & 4 deletions src/tweets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,12 @@ export async function fetchTweets(
}

const variables: Record<string, any> = {
includeHasBirdwatchNotes: false,
rest_id: userId,
userId: userId,
count: maxTweets,
includePromotedContent: false, // true on the website
withQuickPromoteEligibilityTweetFields: true,
withVoice: true,
withV2Timeline: true,
};

if (cursor != null && cursor != '') {
Expand All @@ -116,10 +119,35 @@ export async function fetchTweets(

const params = new URLSearchParams();
params.set('variables', stringify(variables));
params.set('features', stringify(features));
params.set(
'features',
stringify({
rweb_lists_timeline_redesign_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,
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: false,
tweet_awards_web_tipping_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,
longform_notetweets_rich_text_read_enabled: true,
longform_notetweets_inline_media_enabled: true,
responsive_web_media_download_video_enabled: false,
responsive_web_enhance_cards_enabled: false,
}),
);

const res = await requestApi<TimelineV2>(
`https://api.twitter.com/graphql/8IS8MaO-2EN6GZZZb8jF0g/UserWithProfileTweetsAndRepliesQueryV2?${params.toString()}`,
`https://twitter.com/i/api/graphql/XicnWRbyQ3WgVY__VataBQ/UserTweets?${params.toString()}`,
auth,
);

Expand Down

0 comments on commit c0de042

Please sign in to comment.