oauth twitter and email

心不动则不痛 提交于 2020-01-01 09:37:08

问题


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)?


回答1:


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

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




回答2:


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}



回答3:


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




回答4:


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



来源:https://stackoverflow.com/questions/4377633/oauth-twitter-and-email

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!