API returns errors properly now
This commit is contained in:
parent
c1bb5a60c0
commit
ce7f3dd8e6
@ -203,13 +203,21 @@ def extractStatusV2(url,workaroundTokens):
|
|||||||
entries=output['data']['tweet_results']
|
entries=output['data']['tweet_results']
|
||||||
tweetEntry=None
|
tweetEntry=None
|
||||||
for entry in entries:
|
for entry in entries:
|
||||||
|
if 'result' not in entry:
|
||||||
|
continue
|
||||||
result = entry['result']
|
result = entry['result']
|
||||||
if '__typename' in result and result['__typename'] == 'TweetWithVisibilityResults':
|
if '__typename' in result and result['__typename'] == 'TweetWithVisibilityResults':
|
||||||
result=result['tweet']
|
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:
|
if 'rest_id' in result and result['rest_id'] == twid:
|
||||||
tweetEntry=result
|
tweetEntry=result
|
||||||
break
|
break
|
||||||
tweet=tweetEntry
|
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:
|
except Exception as e:
|
||||||
continue
|
continue
|
||||||
return tweet
|
return tweet
|
||||||
|
@ -166,6 +166,12 @@ def twitfix(sub_path):
|
|||||||
tweet = None
|
tweet = None
|
||||||
if tweet is None:
|
if tweet is None:
|
||||||
tweet = twExtract.extractStatusV2(twitter_url,workaroundTokens=config['config']['workaroundTokens'].split(','))
|
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"]
|
tweetL = tweet["legacy"]
|
||||||
if "user_result" in tweet["core"]:
|
if "user_result" in tweet["core"]:
|
||||||
userL = tweet["core"]["user_result"]["result"]["legacy"]
|
userL = tweet["core"]["user_result"]["result"]["legacy"]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user