Question

I'm using OAuth to connect my MVC application with twitter but I can't seem to get external data? Currently I'm using this:

        AuthenticationResult result = OAuthWebSecurity.VerifyAuthentication(Url.Action("ExternalLoginCallback", new { ReturnUrl = returnUrl }));

        var extraData = result.ExtraData;
        if (result.Provider == "facebook")
        {
            emailadres = extraData["username"];
        }
        else if (result.Provider == "twitter")
        {
            emailadres = extraData["username"];
        }

Facebook does give me an email, but Twitter doesn't seem to do that...

Any solutions?

Was it helpful?

Solution

You can get name by querying following endpoint - GET account/verify_credentials

It returns following response. But You cannot get Email or Gender (refer these threads from Twitter forums - No Email, No Gender) from this response.

{
  "name": "Matt Harris",
  "profile_sidebar_border_color": "C0DEED",
  "profile_background_tile": false,
  "profile_sidebar_fill_color": "DDEEF6",
  "location": "San Francisco",
  "profile_image_url": "http://a1.twimg.com/profile_images/554181350/matt_normal.jpg",
  "created_at": "Sat Feb 17 20:49:54 +0000 2007",
  "profile_link_color": "0084B4",
  "favourites_count": 95,
  "url": "http://themattharris.com",
  "contributors_enabled": false,
  "utc_offset": -28800,
  "id": 777925,
  "profile_use_background_image": true,
  "profile_text_color": "333333",
  "protected": false,
  "followers_count": 1025,
  "lang": "en",
  "verified": false,
  "profile_background_color": "C0DEED",
  "geo_enabled": true,
  "notifications": false,
  "description": "Developer Advocate at Twitter. Also a hacker and British expat who is married to @cindyli and lives in San Francisco.",
  "time_zone": "Tijuana",
  "friends_count": 294,
  "statuses_count": 2924,
  "profile_background_image_url": "http://s.twimg.com/a/1276711174/images/themes/theme1/bg.png",
  "status": {
    "coordinates": {
      "coordinates": [
        -122.40075845,
        37.78264991
      ],
      "type": "Point"
    },
    "favorited": false,
    "created_at": "Tue Jun 22 18:17:48 +0000 2010",
    "truncated": false,
    "text": "Going through and updating @twitterapi documentation",
    "contributors": null,
    "id": 16789004997,
    "geo": {
      "coordinates": [
        37.78264991,
        -122.40075845
      ],
      "type": "Point"
    },
    "in_reply_to_user_id": null,
    "place": null,
    "source": "<a href=\"http://itunes.apple.com/app/twitter/id333903271?mt=8\" rel=\"nofollow\">Twitter for iPhone</a>",
    "in_reply_to_screen_name": null,
    "in_reply_to_status_id": null
  },
  "screen_name": "themattharris",
  "following": false
}

EDIT As mentioned by Davis in the comment, one can get email with new API modifications. But I am keeping this answer as is to support the integrity of question.

OTHER TIPS

The API won't return an email address to you. If you're interested in a user's email address, you'll have to ask the user for it within your own application as a completely distinct act.

Not sure about gender, but you can get username and email. See my answers here and here about getting gender.


I have used Twitter framework in my iOS App to get user details and email address. Twitter has provided a beautiful framework for that.

To get user email address, your application should be whitelisted. Here is the link. Go to use this form. You can either send mail to sdk-feedback@twitter.com with some details about your App like Consumer key, App Store link of an App, Link to privacy policy, Metadata, Instructions on how to log into our App etc..They will respond within 2-3 working days.

Here is the story how I got whitelisted by conversation with Twitter support team:

  • Send mail to sdk-feedback@twitter.com with some details about your App like Consumer key, App Store link of an App, Link to privacy policy, Metadata, Instructions on how to log into our App. Mention in mail that you want to access user email adress inside your App.

  • They will review your App and reply to you withing 2-3 business days.

  • Once they say that your App is whitelisted, update your App's settings in Twitter Developer portal. Sign in to apps.twitter.com and:

    1. On the 'Settings' tab, add a terms of service and privacy policy URL
    2. On the 'Permissions' tab, change your token's scope to request email. This option will only been seen, once your App gets whitelisted.

Hope it helps !!!

Requesting a user’s email address requires your application to be whitelisted by Twitter. To request access to a users email address, go here https://support.twitter.com/forms/platform

Once whitelisted, the “Request email addresses from users” checkbox will be available under your app permissions on apps.twitter.com. Privacy Policy URL and Terms of Service URL fields will also be available under settings which are required for email access. If enabled, users will be informed via the oauth/authorize dialog that your app can access their email address.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top