7

is it possible to get user email after he logged by oauth? may be page can ask him if he want to share his email in my application? or any allowed info is what return by url http://api.twitter.com/1/users/show/test.xml (without email)?

kusanagi
  • 14,296
  • 20
  • 86
  • 111
  • possible duplicate of [Is there a way to get an user's email ID after verifying her Twitter identity using OAuth?](http://stackoverflow.com/questions/3599621/is-there-a-way-to-get-an-users-email-id-after-verifying-her-twitter-identity-us) – abyx Nov 09 '11 at 05:54

4 Answers4

7

For anyone interested this is not true anymore.

Follow the guide in this answer to request a special privilege (email access) for your Twitter app: Can we get email ID from Twitter oauth API?

You will need to provide links for your terms of use and privacy policy in your app. Then on permission tab you can check tick Request email addresses from users.

Now when you inquire Twitter API append "?include_email=true" to url (so the full URL would be "https://api.twitter.com/1.1/account/verify_credentials.json?include_email=true"). The parameter is described in twitter documentation: https://dev.twitter.com/rest/reference/get/account/verify_credentials

You can update twitter.py backend in python-social-auth library with this url modification and it will work too ;)

Starting from line 35 in twitter.py backend:

def user_data(self, access_token, *args, **kwargs):
"""Return user data provided"""
return self.get_json(
'https://api.twitter.com/1.1/account/verify_credentials.json?include_email=true',
auth=self.oauth_auth(access_token)
)

and include response.get('email','') few lines above:

def get_user_details(self, response):
        """Return user details from Facebook account"""
        fullname, first_name, last_name = self.get_user_names(
            response.get('name', ''),
            response.get('first_name', ''),
            response.get('last_name', '')
        )
        return {'username': response.get('username', response.get('name')),
                'email': response.get('email', ''),
                'fullname': fullname,
                'first_name': first_name,
                'last_name': last_name}
Community
  • 1
  • 1
collerek
  • 261
  • 2
  • 6
  • for the record, latest version of `python-social-auth` does that already (current version is 0.2.21). It changed in revision 96fc4d1. – Alexandre Oct 14 '16 at 15:57
7

No. The Twitter api does not share email addresses for security reasons.

Update: Twitter has added this functionality. Look at @collerek's answer.

Community
  • 1
  • 1
Ricky Smith
  • 2,379
  • 1
  • 13
  • 29
  • 1
    Is it really about security? The cynic in me is more likely to believe its about ownership of the user. Almost every other similar service provider will share the email, if the user agrees. – UpTheCreek Jul 14 '12 at 22:04
  • 2
    I suppose it could be either. The end result is the same. – Ricky Smith Jul 26 '12 at 16:08
0

I'm using Twiterizzer through C#. My application is already whitelisted so in theory I can get the logged user email.

I do this:

OAuthTokenResponse response = OAuthUtility.GetRequestToken(key, secret, myurl); 
Uri authorizationUrl = OAuthUtility.BuildAuthorizationUri(response.Token);
Response.Redirect(authorizationUrl.AbsoluteUri);

And when I receive the token:

OAuthTokenResponse response = OAuthUtility.GetAccessToken(key, secret, receivedToken, receivedVerifier);

This response has the UserId and the SreenName.

What am I missing in my code for the email?

Thanks

spirit
  • 3,265
  • 2
  • 14
  • 29
0

Now you can get twitter user email address. Checkout full procedure here.

Community
  • 1
  • 1
Pran
  • 1,817
  • 23
  • 23