Skip to content

Commit

Permalink
Add missing token to api calls to Twitter's CDN (#128)
Browse files Browse the repository at this point in the history
* Added changeset

* Added token

* Added changeset

* Updated changeset
  • Loading branch information
lfades authored Aug 14, 2023
1 parent 5637b66 commit dc5cadf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/honest-rabbits-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-tweet': patch
---

Added missing token to API requests to Twitter's CDN
12 changes: 11 additions & 1 deletion packages/react-tweet/src/api/get-tweet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -46,16 +52,20 @@ 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',
'tfw_show_business_affiliate_badge:on',
'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
Expand Down

4 comments on commit dc5cadf

@vercel
Copy link

@vercel vercel bot commented on dc5cadf Aug 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

react-tweet-create-react-app – ./apps/create-react-app

react-tweet-create-react-app-git-main-vercel-labs.vercel.app
create-react-app-gray-seven.vercel.app
react-tweet-create-react-app-vercel-labs.vercel.app

@vercel
Copy link

@vercel vercel bot commented on dc5cadf Aug 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

react-tweet-vite-app – ./apps/vite-app

react-tweet-vite-app-vercel-labs.vercel.app
react-tweet-vite-app.vercel.app
react-tweet-vite-app-git-main-vercel-labs.vercel.app

@vercel
Copy link

@vercel vercel bot commented on dc5cadf Aug 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

react-tweet-custom-tweet-dub – ./apps/custom-tweet-dub

react-tweet-custom-tweet-dub-git-main-vercel-labs.vercel.app
react-tweet-dub.vercel.app
react-tweet-custom-tweet-dub-vercel-labs.vercel.app

@vercel
Copy link

@vercel vercel bot commented on dc5cadf Aug 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.