1
votes

I'm using Oauth1Session for authenticating Twitter and tried to get user's email info. Actually, the application have been successfully fetched user info but it's not included email info. How can I get email info with accouunt/verify_credentials.

My code:

    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': None, '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': None, 'status': {'created_at': 'Sun Dec 22 10:11:00 +0000 2019', 'id': xxxxxxxxxxx, 'id_str': 'xxxxxxxxxxx', 'text': 'xxxxxxxxxxxxxxx', 'truncated': False, 'entities': {'hashtags': [], 'symbols': [], 'user_mentions': [], 'urls': []}, 'source': 'Twitter for iPhone', 'in_reply_to_status_id': None, 'in_reply_to_status_id_str': None, 'in_reply_to_user_id': None, 'in_reply_to_user_id_str': None, 'in_reply_to_screen_name': None, 'geo': None, 'coordinates': None, 'place': None, 'contributors': None, 'is_quote_status': False, 'retweet_count': 0, 'favorite_count': 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': 'xxxxxxxxxxxxxxxxx', 'profile_background_image_url_https': 'xxxxxxxxxxxxxxxx', 'profile_background_tile': False, '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': 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', 'suspended': False, 'needs_phone_verification': False}

But not included email...

1

1 Answers

1
votes

I have updated paramas:

params = {"include_email": "true"}