From 5a6deabd8491f1e234cf1cc5a2f9fb26d7d31de4 Mon Sep 17 00:00:00 2001 From: dangered wolf Date: Thu, 6 Apr 2023 18:29:49 -0400 Subject: [PATCH] Don't use cached tokens for fallback --- src/api/status.ts | 4 ++++ src/fetch.ts | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/api/status.ts b/src/api/status.ts index 8f2d482..a2501a9 100644 --- a/src/api/status.ts +++ b/src/api/status.ts @@ -167,7 +167,11 @@ export const statusAPI = async ( typeof tweet.full_text === 'undefined' && conversation.timeline?.instructions?.length > 0 ) { + console.log('Unfortunately, this Tweet is still not accessible despite trying fallback. Conversation: ', conversation, ' Tweet: ', tweet); return { code: 401, message: 'PRIVATE_TWEET' }; + } else if (typeof tweet.full_text === 'undefined') { + console.log('Accessing the fallback resulted in an error'); + return { code: 500, message: 'API_FAIL' }; } } else { /* {"errors":[{"code":34,"message":"Sorry, that page does not exist."}]} */ diff --git a/src/fetch.ts b/src/fetch.ts index da2cc79..9642269 100644 --- a/src/fetch.ts +++ b/src/fetch.ts @@ -6,10 +6,11 @@ const API_ATTEMPTS = 16; export const twitterFetch = async ( url: string, event: FetchEvent, + fallback = false, validateFunction: (response: unknown) => boolean ): Promise => { let apiAttempts = 0; - let newTokenGenerated = false; + let newTokenGenerated = fallback; const [userAgent, secChUa] = generateUserAgent(); console.log(`Outgoing useragent for this request:`, userAgent); @@ -22,7 +23,7 @@ export const twitterFetch = async ( }; const guestTokenRequest = new Request( - `${Constants.TWITTER_API_ROOT}/1.1/guest/activate.json`, + `${fallback ? Constants.API_FALLBACK_DOMAIN : Constants.TWITTER_API_ROOT}/1.1/guest/activate.json`, { method: 'POST', headers: tokenHeaders, @@ -98,6 +99,7 @@ export const twitterFetch = async ( const guestToken = activateJson.guest_token; + console.log(guestTokenRequest); console.log(newTokenGenerated ? 'Activated guest:' : 'Using guest:', activateJson); console.log('Guest token:', guestToken); @@ -184,6 +186,7 @@ export const fetchConversation = async ( fallback ? Constants.API_FALLBACK_DOMAIN : Constants.TWITTER_API_ROOT }/2/timeline/conversation/${status}.json?${Constants.GUEST_FETCH_PARAMETERS}`, event, + fallback, (_conversation: unknown) => { const conversation = _conversation as TimelineBlobPartial; return !(