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

I tried several SDKs, but could not get the email id from any of the resources. I tried FHSTwitterEngine for this purpose, but I did not get a 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); 
+6
iphone ios5 twitter
Oct 28 '13 at 7:38
source share
3 answers

EDIT

After Twitter has updated the API, the user can now receive email using the 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 (eg 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 (eg attempt to log in or show an alert) } 

NOTES: Even if the user provides access to their email address, it is not guaranteed that you will receive an email address. For example, if someone follows Twitter with a phone number instead of an email address, the email field may be blank. When this happens, the completion block will give an error because there is no email address.

Twitter Dev Ref




PAST

There is NO , since you can get the Twitter user email address.

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

Twitter Doc .

+13
Oct 28 '13 at 8:12
source share

You will need to use the Twitter platform. Twitter has provided an excellent infrastructure for this, you just need to integrate it into your application.

To get the user's email address, your application must be in the white list. Here's the link . Go to use this form . You can send mail to sdk-feedback@twitter.com with some details about your application, for example, in the section "Consumer Key", "App Store" in the application, "Privacy Policy Link", "Metadata", "Instructions for logging into our application, etc. " reply within 2-3 business days.

Here is the story of how I got a whitelist chat with the Twitter support team:

  • Send an email to sdk-feedback@twitter.com with some details about your application, for example, in the section "Consumer Key", in the application "Application Store", "Link to Privacy Policy", "Metadata", "Instructions for logging into our Appendix". Mention in the mail that you want to access the user's email address in your application.

  • They will review your application and respond to you in 2-3 business days.

  • Once they say your application is whitelisted, update your application’s settings on the Twitter developer portal. Sign in to apps.twitter.com and:

    • On the Settings tab, add the URL of the terms of service and privacy policy
    • On the Permissions tab, change the token area for the email request. This option will be displayed only after your application is included in the white list.

Put your hands on the code

Using the Twitter framework:

Get user email address

 -(void)requestUserEmail { 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 { // Handle user not signed in (eg attempt to log in or show an alert) } } 

Get user profile

 -(void)usersShow:(NSString *)userID { NSString *statusesShowEndpoint = @"https://api.twitter.com/1.1/users/show.json"; NSDictionary *params = @{@"user_id": userID}; NSError *clientError; NSURLRequest *request = [[[Twitter sharedInstance] APIClient] URLRequestWithMethod:@"GET" URL:statusesShowEndpoint parameters:params error:&clientError]; if (request) { [[[Twitter sharedInstance] APIClient] sendTwitterRequest:request completion:^(NSURLResponse *response, NSData *data, NSError *connectionError) { if (data) { // handle the response data eg NSError *jsonError; NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonError]; NSLog(@"%@",[json description]); } else { NSLog(@"Error code: %ld | Error description: %@", (long)[connectionError code], [connectionError localizedDescription]); } }]; } else { NSLog(@"Error: %@", clientError); } } 

Hope this helps !!!

+4
May 26 '15 at 11:02
source share

If you need a user’s email address, you need to ask the user for it within your own application and service. The Twitter API does not provide the user's email address as part of the OAuth token negotiation process and does not offer other ways to obtain it.

+2
Jun 21 '14 at 6:50
source share



All Articles