验证Twitter时无法获取Twitter电子邮件

问题描述 投票:1回答:1

我正在使用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':无,'time_zone':无,'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”:[],“符号”:[],“ user_mentions”:[],“ urls”:[]},“ source”:“ Twitter for 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”:False ,'retweet_count':0,'favorite_count':2,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':'xxxxxxxxxxxxxxxx','profile_background_tile':False,'profile_image_url':'xxxxxxxxxxxxxxxx','profile_image_url_https':'xxxx' ':'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':False, '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}

但不包括电子邮件...

python twitter
1个回答
1
投票

我更新了paramas:

params = {"include_email": "true"}
© www.soinside.com 2019 - 2024. All rights reserved.