twitter: retry if possibly missing csrf token

This commit is contained in:
dumbmoron 2024-05-03 09:34:37 +00:00
parent 6c33687279
commit ec4a8c1e3e
No known key found for this signature in database

View File

@ -83,6 +83,16 @@ const requestTweet = async(tweetId, token, cookie) => {
let result = await fetch(graphqlTweetURL, { headers });
updateCookie(cookie, result.headers);
// we might have been missing the `ct0` cookie, retry
if (result.status === 403 && result.headers.get('set-cookie')) {
result = await fetch(graphqlTweetURL, {
headers: {
...headers,
'x-csrf-token': cookie.values().ct0
}
});
}
return result
}