Get user profile data (especially email address) from Twitter on iOS

I am going to get user information based on his / her Twitter account. Now, first of all, let me explain what I want to do.

In my case, the user will be given the option to Register with a Twitter account. Therefore, based on the Twitter user account, I want to get information about the user (for example, email address, name, profile, date of birth, gender, etc.) and save this data in the database. Now many people have probably suggested that I use ACAccount and ACAccountStore , a class that provides an interface for accessing, managing, and storing accounts. But in my case, I want to register the user, even if the user has not configured a Twitter account in the iOS settings application. I want the user to go to the Twitter login screen (in Safari or in the application itself or using any other alternative).

I also submitted Twitter documentation containing an API list here . But I am very confused about how the user should be presented with a login screen for logging into a Twitter account and how I will get profile information. Should I use UIWebView or redirect the user to Safari or accept another way to do this?

+3
ios objective-c twitter-oauth twitter acaccountstore
May 14 '15 at 10:27
source share
4 answers

Twitter has provided an excellent infrastructure for this, you just need to integrate it into your application.

https://dev.twitter.com/twitter-kit/ios

It has a simple login method: -

 // Objective-C TWTRLogInButton* logInButton = [TWTRLogInButton buttonWithLogInCompletion: ^(TWTRSession* session, NSError* error) { if (session) { NSLog(@"signed in as %@", [session userName]); } else { NSLog(@"error: %@", [error localizedDescription]); } }]; logInButton.center = self.view.center; [self.view addSubview:logInButton]; 

This is the process of obtaining user profile information: -

 /* Get user info */ [[[Twitter sharedInstance] APIClient] loadUserWithID:[session userID] completion:^(TWTRUser *user, NSError *error) { // handle the response or error if (![error isEqual:nil]) { NSLog(@"Twitter info -> user = %@ ",user); NSString *urlString = [[NSString alloc]initWithString:user.profileImageLargeURL]; NSURL *url = [[NSURL alloc]initWithString:urlString]; NSData *pullTwitterPP = [[NSData alloc]initWithContentsOfURL:url]; UIImage *profImage = [UIImage imageWithData:pullTwitterPP]; } else { NSLog(@"Twitter error getting profile : %@", [error localizedDescription]); } }]; 

I think that the relaxation you can find on the Twitter Kit Tutorial also allows you to request users email by calling the TwitterAuthClient # requestEmail method, passing in a valid TwitterSession and callback.

+3
May 14 '15 at 10:36
source share

Finally, after a long conversation with sdk-feedback@twitter.com , I got my application on the white list. Here is the story:

  • 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". Indicate in the mail that you want to access the user's email in your application.

  • They will review your application and respond to you within 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:

Accept Vizllx’s statement: "Twitter has provided an excellent foundation for this, you just need to integrate it into your application."

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 !!!

+5
May 27 '15 at 8:06
source share

On Twitter, you can only get user_name and user_id . It is so secure that you cannot receive email id , birth date , gender , etc. Compare with Facebook, Twitter is very confidential to provide data.

need link: link1 .

+3
May 14 '15 at 10:31
source share

How to get twitter email id?

Step 1: got to https://apps.twitter.com/app/

Step 2: click ur app> click permission tab.

Step 3: check your inbox here

enter image description here

+2
Oct 17 '17 at 10:02 on
source share



All Articles