API returns errors properly now

This commit is contained in:
Dylan 2024-01-21 22:07:33 +00:00
parent c1bb5a60c0
commit ce7f3dd8e6
2 changed files with 14 additions and 0 deletions

View File

@ -203,13 +203,21 @@ def extractStatusV2(url,workaroundTokens):
entries=output['data']['tweet_results']
tweetEntry=None
for entry in entries:
if 'result' not in entry:
continue
result = entry['result']
if '__typename' in result and result['__typename'] == 'TweetWithVisibilityResults':
result=result['tweet']
elif '__typename' in result and result['__typename'] == 'TweetUnavailable':
if 'reason' in result:
return {'error':'Tweet unavailable: '+result['reason']}
return {'error':'Tweet unavailable'}
if 'rest_id' in result and result['rest_id'] == twid:
tweetEntry=result
break
tweet=tweetEntry
if tweet is None:
return {'error':'Tweet not found (404); May be due to invalid tweet, changes in Twitter\'s API, or a protected account.'}
except Exception as e:
continue
return tweet

View File

@ -166,6 +166,12 @@ def twitfix(sub_path):
tweet = None
if tweet is None:
tweet = twExtract.extractStatusV2(twitter_url,workaroundTokens=config['config']['workaroundTokens'].split(','))
if 'error' in tweet:
response = make_response(jsonify(tweet), 500)
response.headers['Content-Type'] = 'application/json'
response.cache_control.max_age = 3600
response.cache_control.public = True
return response
tweetL = tweet["legacy"]
if "user_result" in tweet["core"]:
userL = tweet["core"]["user_result"]["result"]["legacy"]