diff --git a/src/api/status.ts b/src/api/status.ts index e5057c8..4b549b1 100644 --- a/src/api/status.ts +++ b/src/api/status.ts @@ -152,6 +152,7 @@ const populateTweetProperties = async ( language.length === 2 && language !== tweet.legacy.lang ) { + console.log(`Attempting to translate Tweet to ${language}...`); const translateAPI = await translateTweet( tweet, conversation.guestToken || '', @@ -252,12 +253,11 @@ export const statusAPI = async ( if (!tweet) { return { code: 404, message: 'NOT_FOUND' }; } - const conversation: any[] = []; /* Creating the response objects */ const response: TweetAPIResponse = { code: 200, message: 'OK' } as TweetAPIResponse; const apiTweet: APITweet = (await populateTweetProperties( tweet, - conversation, + res, language )) as APITweet; @@ -266,7 +266,7 @@ export const statusAPI = async ( if (quoteTweet) { apiTweet.quote = (await populateTweetProperties( quoteTweet, - conversation, + res, language )) as APITweet; } diff --git a/src/helpers/translate.ts b/src/helpers/translate.ts index 79bc2b3..f6437df 100644 --- a/src/helpers/translate.ts +++ b/src/helpers/translate.ts @@ -19,23 +19,33 @@ export const translateTweet = async ( ].join('; '), 'x-csrf-token': csrfToken, 'x-twitter-active-user': 'yes', - 'x-guest-token': guestToken + 'x-guest-token': guestToken, + 'Referer': `${Constants.TWITTER_ROOT}/i/status/${tweet.rest_id}`, }; - let apiRequest; + let translationApiResponse; let translationResults: TranslationPartial; headers['x-twitter-client-language'] = language; + /* As of August 2023, you can no longer fetch translations with guest token */ + if (typeof TwitterProxy === 'undefined') { + return null + } + try { - apiRequest = await fetch( - `${Constants.TWITTER_ROOT}/i/api/1.1/strato/column/None/tweetId=${tweet.rest_id},destinationLanguage=None,translationSource=Some(Google),feature=None,timeout=None,onlyCached=None/translation/service/translateTweet`, + const url = `${Constants.TWITTER_ROOT}/i/api/1.1/strato/column/None/tweetId=${tweet.rest_id},destinationLanguage=None,translationSource=Some(Google),feature=None,timeout=None,onlyCached=None/translation/service/translateTweet`; + console.log(url, headers); + translationApiResponse = await TwitterProxy.fetch( + url, { method: 'GET', headers: headers } ); - translationResults = (await apiRequest.json()) as TranslationPartial; + translationResults = (await translationApiResponse.json()) as TranslationPartial; + + console.log(`translationResults`, translationResults); if (translationResults.translationState !== 'Success') { return null;