Is there a way to get an user's email ID after

2019-01-01 15:21发布

I am new to OAuth and have been playing around with the Twitter API. I am able to fetch the credentials of an user after authentication by making a request to http://api.twitter.com/1/account/verify_credentials.xml. The response contains the user id, screen name etc. but not the email ID.

Is it possible at all to retrieve the email ID of the user?

Update

I believe Facebook provides this information if you specifically request for extended permissions. Is there something similar for Twitter?

9条回答
冷夜・残月
2楼-- · 2019-01-01 15:40

In my case every time I get the response I got a unique authentication id for every user and its same for that user every time. So I used that id to create a email like unique_id@twitter.com and check if that's already on my site ( for first time it is not ) and then register the user. Then if he logins second time I just again create the email and check if its already on there. By this I don't have to make him create a local account first and can identify him to login.

查看更多
回忆,回不去的记忆
3楼-- · 2019-01-01 15:48

Who said it's not possible ???

I have gotten in my iOS App after whitelisting the App. Check my answer here.

查看更多
琉璃瓶的回忆
4楼-- · 2019-01-01 15:48

Who says you cant get users email, the “Request email addresses from users” checkbox is available under the app permissions on apps.twitter.com. Privacy Policy URL and Terms of Service URL fields must be completed in the app settings in order for email address access to function. If enabled, users will be informed via the oauth/authorize dialog that your app can access their email address.

查看更多
临风纵饮
5楼-- · 2019-01-01 15:49

Here is the example how to get twitter user email in Laravel, and on coditty.com you can find the full example using Angular+Laravel

 // get token secret from db 
        $token = TwitterTokens::where('oauth_token', $request->input('oauth_token'))->first(); 


        // open twitter connection
        $connection = new \Abraham\TwitterOAuth\TwitterOAuth(
                        $this->twitter_consumer_key, 
                        $this->twitter_secret, 
                        $request->input('oauth_token'), 
                        $token->oauth_token_secret// twitter secret from DB
                        );

        // get acces token
        $access_token = $connection->oauth("oauth/access_token", ["oauth_verifier" => $request->input('oauth_verifier')]); 

         // new TwitterOAuth instance to get email
        $twitterOAuth = new \Abraham\TwitterOAuth\TwitterOAuth( $this->twitter_consumer_key, $this->twitter_secret, $access_token['oauth_token'], $access_token['oauth_token_secret'] );

        // Let's get the user's info with email
        $twitterUser = $twitterOAuth->get('account/verify_credentials', ['include_entities' => 'false','include_email'=>'true','skip_status'=>'true',]);


        // output user object from twitter in your Log file
        Log::info(['user'=>$twitterUser]);
查看更多
唯独是你
6楼-- · 2019-01-01 15:51

For OutsourceFactor, which is written in Python / Django, I get the username via oAuth1, then construct an email as "username@twitter.com" which is guaranteed to be unique throughout twitter. Then I hash it to get a nice UUID to be used and associated with my local user account. Same thing for Yahoo. Google and Facebook use oAuth2 and they give me the email address on request which is nice.

To ensure multiple social associations with a single account, I allow social account associations ONLY after the user has locally created an account and is logged in.

So, you have to create an account first (local account), then you can use any of the social oAuth providers to ease your future logins. This is the best bang for the buck for my site.

Anyways, you get some unique form of ID from twitter. So just use it. You can ask for an email address later or before the association.

查看更多
墨雨无痕
7楼-- · 2019-01-01 15:56

Email address is obfuscated by Twitter in their OAuth responses. Which always have been a great issue for people wanting to include a "Register with Twitter" function.

More recently (early 2015), Twitter have added email address support through a second service call, but under certain, abused, conditions.

https://dev.twitter.com/rest/reference/get/account/verify_credentials

So now it is possible, but my opinion is to continue to implement an OAuth every-provider-but-twitter single sign on. They must be boycotted until they act normally, i mean like every single other OAuth provider.

查看更多
登录 后发表回答