From dc5cadf14c0d44a588c9758e03a441b30affbb4c Mon Sep 17 00:00:00 2001 From: Luis Alvarez D Date: Mon, 14 Aug 2023 17:41:05 -0500 Subject: [PATCH] Add missing token to api calls to Twitter's CDN (#128) * Added changeset * Added token * Added changeset * Updated changeset --- .changeset/honest-rabbits-swim.md | 5 +++++ packages/react-tweet/src/api/get-tweet.ts | 12 +++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 .changeset/honest-rabbits-swim.md diff --git a/.changeset/honest-rabbits-swim.md b/.changeset/honest-rabbits-swim.md new file mode 100644 index 0000000..79f8a77 --- /dev/null +++ b/.changeset/honest-rabbits-swim.md @@ -0,0 +1,5 @@ +--- +'react-tweet': patch +--- + +Added missing token to API requests to Twitter's CDN diff --git a/packages/react-tweet/src/api/get-tweet.ts b/packages/react-tweet/src/api/get-tweet.ts index 5cfe59c..b36875a 100644 --- a/packages/react-tweet/src/api/get-tweet.ts +++ b/packages/react-tweet/src/api/get-tweet.ts @@ -24,6 +24,12 @@ export class TwitterApiError extends Error { const TWEET_ID = /^[0-9]+$/ +function getToken(id: string) { + return ((Number(id) / 1e15) * Math.PI) + .toString(6 ** 2) + .replace(/(0+|\.)/g, '') +} + /** * Fetches a tweet from the Twitter syndication API. */ @@ -46,8 +52,11 @@ export async function getTweet( 'tfw_follower_count_sunset:true', 'tfw_tweet_edit_backend:on', 'tfw_refsrc_session:on', + 'tfw_fosnr_soft_interventions_enabled:on', + 'tfw_show_birdwatch_pivots_enabled:on', 'tfw_show_business_verified_badge:on', 'tfw_duplicate_scribes_to_settings:on', + 'tfw_use_profile_image_shape_enabled:on', 'tfw_show_blue_verified_badge:on', 'tfw_legacy_timeline_sunset:true', 'tfw_show_gov_verified_badge:on', @@ -55,7 +64,8 @@ export async function getTweet( 'tfw_tweet_edit_frontend:on', ].join(';') ) - + url.searchParams.set('token', getToken(id)) + const res = await fetch(url.toString(), fetchOptions) const isJson = res.headers.get('content-type')?.includes('application/json') const data = isJson ? await res.json() : undefined