Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get user email address via Twitter API in iOS?

I have tried multiple SDK's but was unable to get an email ID from any of the resources. I have tried FHSTwitterEngine for this purpose but I didn't get the solution.

FHSTwitterEngine *twitterEngine = [FHSTwitterEngine sharedEngine];
NSString *username = [twitterEngine loggedInUsername]; //self.engine.loggedInUsername;
NSString *key = [twitterEngine accessToken].key;
NSString *secrete = [twitterEngine accessToken].secret;

if (username.length > 0)
{
    NSDictionary *userProfile = [[FHSTwitterEngine sharedEngine] getProfileUsername:username];
    NSLog(@"userProfile: %@", userProfile);
like image 394
Bunty Baba Avatar asked Oct 28 '13 07:10

Bunty Baba


People also ask

How will you use the Twitter API or Twitter data?

The Twitter API lets you read and write Twitter data. Thus, you can use it to compose tweets, read profiles, and access your followers' data and a high volume of tweets on particular subjects in specific locations. API stands for Application Programming Interface.


1 Answers

EDIT

After Twitter has updated APIs, Now user can get Email using TWTRShareEmailViewController class.

// Objective-C
if ([[Twitter sharedInstance] session]) {
    TWTRShareEmailViewController* shareEmailViewController = [[TWTRShareEmailViewController alloc] initWithCompletion:^(NSString* email, NSError* error) {
        NSLog(@"Email %@, Error: %@", email, error);
    }];
    [self presentViewController:shareEmailViewController animated:YES completion:nil];
} else {
  // TODO: Handle user not signed in (e.g. attempt to log in or show an alert)
}

// Swift
if Twitter.sharedInstance().session {
  let shareEmailViewController = TWTRShareEmailViewController() { email, error in
    println("Email \(email), Error: \(error)")
  }
  self.presentViewController(shareEmailViewController, animated: true, completion: nil)
} else {
  // TODO: Handle user not signed in (e.g. attempt to log in or show an alert)
}

NOTES: Even if the user grants access to her email address, it is not guaranteed you will get an email address. For example, if someone signed up for Twitter with a phone number instead of an email address, the email field may be empty. When this happens, the completion block will pass an error because there is no email address available.

Twitter Dev Ref


PAST

There is NO way you can get email address of a twitter user.

The Twitter API does not provide the user's email address as part of the OAuth token negotiation process nor does it offer other means to obtain it.

Twitter Doc.

like image 137
Toseef Khilji Avatar answered Sep 19 '22 00:09

Toseef Khilji