Skip to content

Instantly share code, notes, and snippets.

@ianmuchina
Created April 26, 2023 21:09
Show Gist options
  • Save ianmuchina/abcae7b61cb42b0cc30eadf41b9eca46 to your computer and use it in GitHub Desktop.
Save ianmuchina/abcae7b61cb42b0cc30eadf41b9eca46 to your computer and use it in GitHub Desktop.
export async function TweetResultByRestID(tweetId: string, headers: HeadersInit): Promise<any> {
let url = "https://api.twitter.com/graphql/ncDeACNGIApPMaqGVuF_rw/TweetResultByRestId"
const variables = {
tweetId: tweetId,
includePromotedContent: true,
withBirdwatchNotes: true,
withCommunity: true,
withDownvotePerspective: true,
withReactionsMetadata: true,
withReactionsPerspective: true,
withSuperFollowsTweetFields: true,
withSuperFollowsUserFields: true,
withVoice: true,
}
const features = {
freedom_of_speech_not_reach_fetch_enabled: true,
graphql_is_translatable_rweb_tweet_is_translatable_enabled: true,
interactive_text_enabled: true,
longform_notetweets_consumption_enabled: true,
longform_notetweets_richtext_consumption_enabled: true,
responsive_web_edit_tweet_api_enabled: true,
responsive_web_enhance_cards_enabled: true,
responsive_web_graphql_exclude_directive_enabled: true,
responsive_web_graphql_skip_user_profile_image_extensions_enabled: true,
responsive_web_graphql_timeline_navigation_enabled: true,
responsive_web_text_conversations_enabled: true,
responsive_web_twitter_blue_verified_badge_is_enabled: true,
standardized_nudges_misinfo: true,
tweet_awards_web_tipping_enabled: true,
tweet_with_visibility_results_prefer_gql_limited_actions_policy_enabled: true,
tweetypie_unmention_optimization_enabled: true,
verified_phone_label_enabled: true,
vibe_api_enabled: true,
view_counts_everywhere_api_enabled: true,
}
url = `${url}?variables=${encodeURI(JSON.stringify(variables))}&features=${encodeURI(JSON.stringify(features))}`
const response = await fetch(url, { method: 'GET', headers: headers })
const json = await response.json();
return json
}
async function genHeaders() {
const url = "https://api.twitter.com/1.1/guest/activate.json";
const bearer =
`AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs=1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA`;
const response = await fetch(url, {
method: "POST",
headers: {
"Authorization": `Bearer ${bearer}`
},
});
const json = await response.json();
return {
"Authorization": `Bearer ${bearer}`,
"X-Guest-Token": json.guest_token,
};
}
console.log(JSON.stringify(await TweetResultByRestID("20", await genHeaders()), null, " "))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment