我正在使用Oauth1Session对Twitter进行身份验证,并试图获取用户的电子邮件信息。实际上,该应用程序已成功获取用户信息,但不包括电子邮件信息。如何通过accouunt/verify_credentials
获取电子邮件信息。
我的代码:
access_token_url = 'https://api.twitter.com/oauth/access_token'
protected_url = 'https://api.twitter.com/1.1/account/verify_credentials.json'
oauth_token = request.args.get('oauth_token')
oauth_verifier = request.args.get('oauth_verifier')
twitter = OAuth1Session(
client_id,
client_secret,
oauth_token,
oauth_verifier
)
response = twitter.post(
access_token_url,
params={'oauth_verifier': oauth_verifier}
)
access_token = dict(parse_qsl(response.content.decode("utf-8")))
oauth = OAuth1Session(
client_id,
client_secret=client_secret,
resource_owner_key=access_token["oauth_token"],
resource_owner_secret=access_token["oauth_token_secret"]
)
params = {"include_email": True}
response = oauth.get(protected_url, params = params)
user_info = response.json()
user_info
{'id':xxxxxxxxx,'id_str':'xxxxxxxx','name':'xxxxxxxx','screen_name':'xxxxxxxxxx','location':'xxxxxxxxxxxxx','description':'xxxxxxxxxxxx', 'url':无,'entities':{'description':{'urls:[]}},'protected':False,'followers_count':xxx,'friends_count':xx,'listed_count':xx,' created_at':'Thu Aug 27 14:16:29 +0000 2015','favourites_count':xxxx,'utc_offset':None,'time_zone':None,'geo_enabled':True,'verified':False,'statuses_count' :xxxxx,'lang':无,'status':{'created_at':'Sun Dec 22 10:11:00 +0000 2019','id':xxxxxxxxxxx,'id_str':'xxxxxxxxxxx','text': 'xxxxxxxxxxxxxxx','被截断':False,'实体':{'hashtags':[],'symbols':[],'user_mentions':[],'urls':[]},'source':'Twitter对于iPhone','in_reply_to_status_id':无,'in_reply_to_status_id_str':无,'in_reply_to_user_id':无,'in_reply_to_user_id_str':无,'in_reply_to_screen_name':无,'geo':无,'坐标'无,“贡献者”:无,“ is_quote_status”:错误e,'retweet_count':0,'favorite_count':2,2,'favorited':False,'retweeted':False,'lang':'ja'},'contributors_enabled':False,'is_translator':False,'is_translation_enabled' :False,'profile_background_color':'000000','profile_background_image_url':'xxxxxxxxxxxxxxxxxxxx','profile_background_image_url_https':'xxxxxxxxxxxxxxxxxxx','profile_background_tile':False,'profile_image_url':'xxxxxxxxxxxxxxxxxxx','profile_image_url_https':'xxxxxxxxxxxxxxxx' profile_banner_url':'xxxxxxxxxxxxxxxxxx','profile_link_color':'DD2E44','profile_sidebar_border_color':'000000','profile_sidebar_fill_color':'000000','profile_text_color':'000000','profile_use_background_image':False,'has_extended_profile' ,'default_profile':False,'default_profile_image':False,'can_media_tag':False,'followed_by':False,'following':False,'follow_request_sent':False,'notifications':False,'translator_type':'none' ,“已暂停”:False,“ needs_phone_verification”:False}
但不包括电子邮件...
答案 0 :(得分:1)
我更新了paramas:
params = {"include_email": "true"}