如何使用iOS中的Twitter套件获取记录的用户详细信息(图像URL,用户名,电子邮件等)



登录后如何从我的Twitter帐户中获取电子邮件ID,用户名和图像URL,

当前代码是:

[[Twitter sharedInstance] logInWithCompletion:^ (TWTRSession *session, NSError *error)
 {
     if (session)
     {
         NSLog(@"signed in as %@", [session userName]);
     }
     else
     {
         NSLog(@"error: %@", [error localizedDescription]);
     }
 }];

可能会有所帮助,遵循获得profImageemailId的代码。

TWTRLogInButton *logInButton = [TWTRLogInButton buttonWithLogInCompletion:^(TWTRSession *session, NSError *error) {
    // play with Twitter session
    if (session) {
        NSLog(@"Twitter signed in as -> name = %@ id = %@ ", [session userName],[session userID]);
        /* 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]);
             }
         }];
    } else {
        NSLog(@"Twitter error signed in : %@", [error localizedDescription]);
    }
}];
// 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 (e.g. attempt to log in or show an alert)
    }
}

相关内容

最新更新