Is there a way to get an user's email ID after verifying his/her Twitter identity using OAuth?

Solution 1:

The user's email address can not be retrieved via the API. This is a deliberate design decision by the API team.

UPDATE 2015.08.18:

It is possible to request an email address from users, but it requires your app to be whitelisted. See https://dev.twitter.com/rest/reference/get/account/verify_credentials for details of the API call and this form to request whitelisting of your app.

Solution 2:

For OutsourceFactor, which is written in Python / Django, I get the username via oAuth1, then construct an email as "[email protected]" 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.

Solution 3:

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.

Solution 4:

In Android using Fabric, I request the user's email address like this:

TwitterAuthClient authClient = new TwitterAuthClient();

authClient.requestEmail(session, new Callback<String>() {

    @Override
    public void success(Result<String> result) {
        // Do something with the result, which provides the email address
    }

    @Override
    public void failure(TwitterException exception) {
      // Do something on failure
    }
});

See http://docs.fabric.io/android/twitter/request-user-email-address.html

Solution 5:

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 [email protected] 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.