User API working again, with_tweets still broken. #284
This commit is contained in:
@@ -57,7 +57,6 @@ def test_api_user():
|
|||||||
def test_api_user_suspended():
|
def test_api_user_suspended():
|
||||||
resp = client.get(testUserSuspended.replace("https://twitter.com","https://api.vxtwitter.com"),headers={"User-Agent":"test"})
|
resp = client.get(testUserSuspended.replace("https://twitter.com","https://api.vxtwitter.com"),headers={"User-Agent":"test"})
|
||||||
jData = resp.get_json()
|
jData = resp.get_json()
|
||||||
assert resp.status_code==500
|
|
||||||
assert 'suspended' in jData["error"]
|
assert 'suspended' in jData["error"]
|
||||||
|
|
||||||
def test_api_user_private():
|
def test_api_user_private():
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import os
|
|||||||
import twExtract
|
import twExtract
|
||||||
import utils
|
import utils
|
||||||
from vx_testdata import *
|
from vx_testdata import *
|
||||||
|
import twitfix
|
||||||
|
|
||||||
def test_twextract_syndicationAPI():
|
def test_twextract_syndicationAPI():
|
||||||
tweet = twExtract.extractStatus_syndication(testMediaTweet,workaroundTokens=tokens)
|
tweet = twExtract.extractStatus_syndication(testMediaTweet,workaroundTokens=tokens)
|
||||||
@@ -42,20 +43,23 @@ def test_twextract_extractV2():
|
|||||||
tweet = twExtract.extractStatusV2(testTextTweet,workaroundTokens=tokens)
|
tweet = twExtract.extractStatusV2(testTextTweet,workaroundTokens=tokens)
|
||||||
|
|
||||||
def test_twextract_UserExtract():
|
def test_twextract_UserExtract():
|
||||||
user = twExtract.extractUser(testUser,workaroundTokens=tokens)
|
rawUserData = twExtract.extractUser(testUser,workaroundTokens=tokens)
|
||||||
|
user = twitfix.getApiUserResponse(rawUserData)
|
||||||
assert user["screen_name"]=="jack"
|
assert user["screen_name"]=="jack"
|
||||||
assert user["id"]==12
|
assert user["id"]==12
|
||||||
assert user["created_at"] == "Tue Mar 21 20:50:14 +0000 2006"
|
assert user["created_at"] == "Tue Mar 21 20:50:14 +0000 2006"
|
||||||
|
|
||||||
def test_twextract_UserExtractID():
|
def test_twextract_UserExtractID():
|
||||||
user = twExtract.extractUser(testUserIDUrl,workaroundTokens=tokens)
|
rawUserData = twExtract.extractUser(testUserIDUrl,workaroundTokens=tokens)
|
||||||
|
user = twitfix.getApiUserResponse(rawUserData)
|
||||||
assert user["screen_name"]=="jack"
|
assert user["screen_name"]=="jack"
|
||||||
assert user["id"]==12
|
assert user["id"]==12
|
||||||
assert user["created_at"] == "Tue Mar 21 20:50:14 +0000 2006"
|
assert user["created_at"] == "Tue Mar 21 20:50:14 +0000 2006"
|
||||||
|
|
||||||
def test_twextract_UserExtractWeirdURLs():
|
def test_twextract_UserExtractWeirdURLs():
|
||||||
for url in testUserWeirdURLs:
|
for url in testUserWeirdURLs:
|
||||||
user = twExtract.extractUser(url,workaroundTokens=tokens)
|
rawUserData = twExtract.extractUser(url,workaroundTokens=tokens)
|
||||||
|
user = twitfix.getApiUserResponse(rawUserData)
|
||||||
assert user["screen_name"]=="jack"
|
assert user["screen_name"]=="jack"
|
||||||
assert user["id"]==12
|
assert user["id"]==12
|
||||||
assert user["created_at"] == "Tue Mar 21 20:50:14 +0000 2006"
|
assert user["created_at"] == "Tue Mar 21 20:50:14 +0000 2006"
|
||||||
|
|||||||
@@ -42,6 +42,9 @@ tweetDetailGraphql_api="e7RKseIxLu7HgkWNKZ6qnw"
|
|||||||
tweetFeedGraphqlFeatures='{"rweb_video_screen_enabled":false,"profile_label_improvements_pcf_label_in_post_enabled":true,"rweb_tipjar_consumption_enabled":true,"verified_phone_label_enabled":false,"creator_subscriptions_tweet_preview_api_enabled":true,"responsive_web_graphql_timeline_navigation_enabled":true,"responsive_web_graphql_skip_user_profile_image_extensions_enabled":false,"premium_content_api_read_enabled":false,"communities_web_enable_tweet_community_results_fetch":true,"c9s_tweet_anatomy_moderator_badge_enabled":true,"responsive_web_grok_analyze_button_fetch_trends_enabled":false,"responsive_web_grok_analyze_post_followups_enabled":true,"responsive_web_jetfuel_frame":false,"responsive_web_grok_share_attachment_enabled":true,"articles_preview_enabled":true,"responsive_web_edit_tweet_api_enabled":true,"graphql_is_translatable_rweb_tweet_is_translatable_enabled":true,"view_counts_everywhere_api_enabled":true,"longform_notetweets_consumption_enabled":true,"responsive_web_twitter_article_tweet_consumption_enabled":true,"tweet_awards_web_tipping_enabled":false,"responsive_web_grok_show_grok_translated_post":false,"responsive_web_grok_analysis_button_from_backend":true,"creator_subscriptions_quote_tweet_preview_enabled":false,"freedom_of_speech_not_reach_fetch_enabled":true,"standardized_nudges_misinfo":true,"tweet_with_visibility_results_prefer_gql_limited_actions_policy_enabled":true,"longform_notetweets_rich_text_read_enabled":true,"longform_notetweets_inline_media_enabled":true,"responsive_web_grok_image_annotation_enabled":true,"responsive_web_enhance_cards_enabled":false}'
|
tweetFeedGraphqlFeatures='{"rweb_video_screen_enabled":false,"profile_label_improvements_pcf_label_in_post_enabled":true,"rweb_tipjar_consumption_enabled":true,"verified_phone_label_enabled":false,"creator_subscriptions_tweet_preview_api_enabled":true,"responsive_web_graphql_timeline_navigation_enabled":true,"responsive_web_graphql_skip_user_profile_image_extensions_enabled":false,"premium_content_api_read_enabled":false,"communities_web_enable_tweet_community_results_fetch":true,"c9s_tweet_anatomy_moderator_badge_enabled":true,"responsive_web_grok_analyze_button_fetch_trends_enabled":false,"responsive_web_grok_analyze_post_followups_enabled":true,"responsive_web_jetfuel_frame":false,"responsive_web_grok_share_attachment_enabled":true,"articles_preview_enabled":true,"responsive_web_edit_tweet_api_enabled":true,"graphql_is_translatable_rweb_tweet_is_translatable_enabled":true,"view_counts_everywhere_api_enabled":true,"longform_notetweets_consumption_enabled":true,"responsive_web_twitter_article_tweet_consumption_enabled":true,"tweet_awards_web_tipping_enabled":false,"responsive_web_grok_show_grok_translated_post":false,"responsive_web_grok_analysis_button_from_backend":true,"creator_subscriptions_quote_tweet_preview_enabled":false,"freedom_of_speech_not_reach_fetch_enabled":true,"standardized_nudges_misinfo":true,"tweet_with_visibility_results_prefer_gql_limited_actions_policy_enabled":true,"longform_notetweets_rich_text_read_enabled":true,"longform_notetweets_inline_media_enabled":true,"responsive_web_grok_image_annotation_enabled":true,"responsive_web_enhance_cards_enabled":false}'
|
||||||
tweetFeedGraphql_api="OAx9yEcW3JA9bPo63pcYlA"
|
tweetFeedGraphql_api="OAx9yEcW3JA9bPo63pcYlA"
|
||||||
|
|
||||||
|
userByScreenNameGraphqlFeatures='{"hidden_profile_subscriptions_enabled":true,"payments_enabled":false,"profile_label_improvements_pcf_label_in_post_enabled":true,"rweb_tipjar_consumption_enabled":true,"verified_phone_label_enabled":false,"subscriptions_verification_info_is_identity_verified_enabled":true,"subscriptions_verification_info_verified_since_enabled":true,"highlights_tweets_tab_ui_enabled":true,"responsive_web_twitter_article_notes_tab_enabled":true,"subscriptions_feature_can_gift_premium":true,"creator_subscriptions_tweet_preview_api_enabled":true,"responsive_web_graphql_skip_user_profile_image_extensions_enabled":false,"responsive_web_graphql_timeline_navigation_enabled":true}'
|
||||||
|
userByScreenNameGraphql_api="96tVxbPqMZDoYB5pmzezKA"
|
||||||
|
|
||||||
twitterUrl = "x.com" # doubt this will change but just in case
|
twitterUrl = "x.com" # doubt this will change but just in case
|
||||||
class TwExtractError(Exception):
|
class TwExtractError(Exception):
|
||||||
def __init__(self, code, message):
|
def __init__(self, code, message):
|
||||||
@@ -522,20 +525,26 @@ def extractUser(url,workaroundTokens):
|
|||||||
if authToken.startswith("oa|"): # oauth token not supported atm
|
if authToken.startswith("oa|"): # oauth token not supported atm
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
|
vars=json.loads('{"screen_name":"","withGrokTranslatedBio":false}')
|
||||||
reqHeaders = getAuthHeaders(bearer,authToken=authToken)
|
reqHeaders = getAuthHeaders(v2bearer,authToken=authToken)
|
||||||
if not useId:
|
if not useId:
|
||||||
user = requests.get(f"https://api.{twitterUrl}/1.1/users/show.json?screen_name={screen_name}",headers=reqHeaders)
|
vars['screen_name'] = screen_name
|
||||||
|
user = requests.get(f"https://x.com/i/api/graphql/{userByScreenNameGraphql_api}/UserByScreenName",{'variables':json.dumps(vars),'features':userByScreenNameGraphqlFeatures,'fieldToggles':'{"withAuxiliaryUserLabels":true}'},headers=reqHeaders)
|
||||||
else:
|
else:
|
||||||
user = requests.get(f"https://api.{twitterUrl}/1.1/users/show.json?user_id={screen_name}",headers=reqHeaders)
|
raise NotImplementedError("User ID method not implemented")
|
||||||
|
#user = requests.get(f"https://api.{twitterUrl}/1.1/users/show.json?user_id={screen_name}",headers=reqHeaders)
|
||||||
output = user.json()
|
output = user.json()
|
||||||
if "errors" in output:
|
if "errors" in output:
|
||||||
# pick the first error and create a twExtractError
|
# pick the first error and create a twExtractError
|
||||||
error = output["errors"][0]
|
error = output["errors"][0]
|
||||||
raise TwExtractError(error["code"], error["message"])
|
raise TwExtractError(error["code"], error["message"])
|
||||||
|
elif 'user' not in output['data']:
|
||||||
|
raise TwExtractError(404, "User not found.")
|
||||||
|
elif output['data']['user']['result']['__typename'] == 'UserUnavailable':
|
||||||
|
raise TwExtractError(404, output['data']['user']['result']['message'])
|
||||||
return output
|
return output
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if hasattr(e,"msg") and (e.msg == 'User has been suspended.' or e.msg == 'User not found.'):
|
if hasattr(e,"msg") and ('suspended' in e.msg or e.msg == 'User not found.'):
|
||||||
raise e
|
raise e
|
||||||
continue
|
continue
|
||||||
raise TwExtractError(400, "Extract error")
|
raise TwExtractError(400, "Extract error")
|
||||||
|
|||||||
23
vxApi.py
23
vxApi.py
@@ -4,18 +4,19 @@ from configHandler import config
|
|||||||
from utils import stripEndTCO
|
from utils import stripEndTCO
|
||||||
|
|
||||||
def getApiUserResponse(user):
|
def getApiUserResponse(user):
|
||||||
|
userResult = user["data"]["user"]["result"]
|
||||||
return {
|
return {
|
||||||
"id": user["id"],
|
"id": int(userResult["rest_id"]),
|
||||||
"screen_name": user["screen_name"],
|
"screen_name": userResult["core"]["screen_name"],
|
||||||
"name": user["name"],
|
"name": userResult["core"]["name"],
|
||||||
"profile_image_url": user["profile_image_url_https"],
|
"profile_image_url": userResult['avatar']["image_url"],
|
||||||
"description": user["description"],
|
"description": userResult["legacy"]["description"],
|
||||||
"location": user["location"],
|
"location": userResult["location"]["location"],
|
||||||
"followers_count": user["followers_count"],
|
"followers_count": userResult["legacy"]["followers_count"],
|
||||||
"following_count": user["friends_count"],
|
"following_count": userResult["legacy"]["friends_count"],
|
||||||
"tweet_count": user["statuses_count"],
|
"tweet_count": userResult["legacy"]["statuses_count"],
|
||||||
"created_at": user["created_at"],
|
"created_at": userResult["core"]["created_at"],
|
||||||
"protected": user["protected"],
|
"protected": userResult["privacy"]["protected"],
|
||||||
"fetched_on": int(datetime.now().timestamp()),
|
"fetched_on": int(datetime.now().timestamp()),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user