【发布时间】:2020-04-15 03:51:13
【问题描述】:
我正在使用 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()
用户信息
{'id': xxxxxxxxx, 'id_str': 'xxxxxxxx', 'name': 'xxxxxxxx', 'screen_name': 'xxxxxxxxxx', 'location': 'xxxxxxxxxxxxx', 'description': 'xxxxxxxxxxxx', 'url':无,'entities':{'description':{'urls':[]}},'protected':假,'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, 'favorited': False, 'retweeted': False, 'lang': 'ja'}, 'contributors_enabled': False, 'is_translator': False, 'is_translation_enabled' :假,'profile_background_color':'000000','profile_background_image_url':'xxxxxxxxxxxxxxxxx','profile_background_image_url_https':'xxxxxxxxxxxxxxxxxx','profile_background_tile':假,'profile_image_url':'xxxxxxxxxxxxxxxx','profile_image_url_https':'xxxxxxxxxxxxxxxxxxx',' 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':假,'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}
但不包括电子邮件...
【问题讨论】: