-1

Here is some code to get details from Twitter api. I'm new for Twitter integration in iOS applications. I'm new for this implementation.

-(void)TwitterAction {

TWTRSessionStore *store = [[Twitter sharedInstance] sessionStore];
    NSString *userID = store.session.userID;
    if (userID)
        [store logOutUserID:userID];
    [[Twitter sharedInstance] logInWithCompletion:^(TWTRSession *session, NSError *error) {
        if (session) {
            [self usersShow:session.userID];

        } else
            NSLog(@"Error: %@", [error localizedDescription]);
    }];
}

-(void)usersShow:(NSString *)userID {

//NSString *statusesShowEndpoint =[NSString stringWithFormat:@"https://api.twitter.com/1.1/favorites/create.json?id=%@",userID];

NSString *statusesShowEndpoint = @"https://api.twitter.com/1.1/users/show.json";
NSDictionary *params = @{@"user_id": userID};
NSError *clientError;
TWTRAPIClient *client = [TWTRAPIClient clientWithCurrentUser];
NSURLRequest *request = [client URLRequestWithMethod:@"GET" URL:statusesShowEndpoint parameters:params error:&clientError];
if (request)
{
    [client sendTwitterRequest:request completion:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        if (data)
        {
            // handle the response data e.g.
            NSError *jsonError;
            NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonError];
            userDict = @{@"name":[self dictonaryContainKey:json key:@"name"],@"imageUrl":[self dictonaryContainKey:json key:@"profile_image_url"],@"userName":[self dictonaryContainKey:json key:@"screen_name"],@"email":[self dictonaryContainKey:json key:@"gmail"],@"gender":[self dictonaryContainKey:json key:@"gender"]};

            [self CreateAccountBySocialNetworks];

        }
        else
            NSLog(@"Error code: %ld | Error description: %@", (long)[connectionError code], [connectionError localizedDescription]);
    }];
}
else
    NSLog(@"Error: %@", clientError);



}
halfer
  • 19,824
  • 17
  • 99
  • 186
  • 1
    Is this your complete code? Have you tested it? What is the result? "Check out this code!" is insufficient. Pretend it's Jeopardy and structure your post in the form of a question. – sorak Mar 08 '18 at 07:20
  • Hi can you check my question I update it @sorak – Saiprabhakar Mar 08 '18 at 07:39
  • There is still no specific problem statement here. What problem are you getting exactly? – halfer Mar 08 '18 at 10:44
  • I need email and username from twitter so I just use above code @halfer – Saiprabhakar Mar 09 '18 at 11:54
  • What do you mean by "I need email and username from Twitter"? Whose email and username? Is this someone going through a Twitter-based authentication system? – halfer Mar 09 '18 at 12:12
  • Yes, I integrated twitter login by as they mentioned procedure . after that I fallow above code . when user login into twitter and its redirect with some information to our application. In that information I did get user name and mail id . @halfer – Saiprabhakar Mar 09 '18 at 12:45

1 Answers1

0

It is possible to request an email address from users, but it requires your app to be whitelisted. refer this : Get user profile details (especially email address) from twitter in iOS

foram
  • 169
  • 5