Python - verify_credentials return without the email

oauth
python
email

#1
  • the app is white listed
  • got the terms of service & privacy policy
  • checked the check box to fetch email

using the following code:

twitter = Twython(app_key=TWITTER_CONSUMER_KEY,
app_secret=TWITTER_CONSUMER_SECRET,
oauth_token=TWITTER_ACCESS_TOKEN,
oauth_token_secret=settings.TWITTER_TOKEN_SECRET)

obj = twitter.verify_credentials(
    include_email="true", skip_status=1, include_entities=0)
if "email" in obj.keys():
    return obj["email"]twitter = Twython(app_key=settings.TWITTER_CONSUMER_KEY,
                  app_secret=settings.TWITTER_CONSUMER_SECRET,
                oauth_token=settings.TWITTER_ACCESS_TOKEN,
                  oauth_token_secret=settings.TWITTER_TOKEN_SECRET)
obj = twitter.verify_credentials(
    include_email="true", skip_status=1, include_entities=0)
if "email" in obj.keys():
    return obj["email"]

also tried:

verify_creds_url = 'https://api.twitter.com/1.1/account/verify_credentials.json?include_email=true&skip_status=false'
    consumer = oauth.Consumer(settings.TWITTER_CONSUMER_KEY,
                              settings.TWITTER_CONSUMER_SECRET)
    token = oauth.Token(settings.TWITTER_ACCESS_TOKEN,
                        settings.TWITTER_TOKEN_SECRET)
    client = oauth.Client(consumer, token)
    resp, content = client.request(verify_creds_url, "GET")

keep not getting the email
checking on a verified twitter user with a verified email…

any thoughts? what have i missed? at the beginning i though maybe it doesn’t work because the authorization key doesn’t include the params but skip_status works great so it can’t really be that


#2

Have you invalidated any existing user token and had the user sign in to your app again, to get the new privileges?


#3

by revalidating the user you mean had the authorize screen to revalidate the user to allow getting the email?
if so this is done


#4

OK great.

As another debugging step, are you able to use twurl with the same app ID and consumer tokens to hit the verify_credentials endpoint? I guess you’ll see the same result as in your second code snippet, just wondering.

You could try regenerating your app access token and secret and then re-authenticating, but that should not be required.


#5

I just tried this in the REPL (formatting added to show the email entity)

Python 2.7.12 (default, Jul 18 2016, 12:29:00)
[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from twython import Twython
>>> twitter = Twython(app_key="xxxxxxx",
... app_secret="xxxxxxx",
... oauth_token="xxxxxxx",
... oauth_token_secret="xxxxxxx")
>>> obj = twitter.verify_credentials(
...     include_email="true", skip_status=1, include_entities=0)
>>> obj
{u'follow_request_sent': False, u'has_extended_profile': True, u'profile_use_background_image': True, u'default_profile_image': False, u'id': 786491, u'profile_background_image_url_https': u'https://abs.twimg.com/images/themes/theme18/bg.gif', u'verified': False, u'profile_text_color': u'333333', 
u'profile_image_url_https': u'https://pbs.twimg.com/profile_images/753281917944893440/63g61GqD_normal.jpg', u'profile_sidebar_fill_color': u'F6F6F6', u'entities': {u'url': {u'urls': [{u'url': u'https://t.co/NHdjmR0THP', u'indices': [0, 23], u'expanded_url': u'http://about.me/andypiper', u'display_url': u'about.me/andypiper'}]}, 
u'description': {u'urls': []}}, u'followers_count': 13541, u'profile_sidebar_border_color': u'FFFFFF', u'id_str': u'786491', u'profile_background_color': u'ACDEEE', 
*u'email': u'xxxxxxx@xxxxxx.xxxxx'* <----
, u'listed_count': 781, u'is_translation_enabled': False, u'utc_offset': 3600, u'statuses_count': 89892, u'description': u"I'm on the @TwitterDev team, supporting and listening to developers working on the Twitter platform. Code, community, and respect. #HeForShe", u'friends_count': 3899, u'location': u'Kingston upon Thames, London', 
u'profile_link_color': u'6EA8E6', u'profile_image_url': u'http://pbs.twimg.com/profile_images/753281917944893440/63g61GqD_normal.jpg', u'following': False, u'geo_enabled': True, u'profile_banner_url': u'https://pbs.twimg.com/profile_banners/786491/1468424285', 
u'profile_background_image_url': u'http://abs.twimg.com/images/themes/theme18/bg.gif', u'screen_name': u'andypiper', u'lang': u'en', u'profile_background_tile': False, u'favourites_count': 65502, u'name': u'Pipes', u'notifications': False, 
u'url': u'https://t.co/NHdjmR0THP', u'created_at': u'Wed Feb 21 15:14:48 +0000 2007', u'contributors_enabled': False, u'time_zone': u'London', u'protected': False, u'default_profile': False, u'is_translator': False}
>>>