【问题标题】:Facebook SDK iOS use user dataFacebook SDK iOS 使用用户数据
【发布时间】:2015-07-27 11:25:57
【问题描述】:

登录时如何获取用户名、用户图片、用户邮箱:didCompleteWithResult: err: 方法在 Facebook SDK for iOS 4.4 版本中调用。 我想将这些值设置为属性。

- (void)loginButton:(FBSDKLoginButton *)loginButton didCompleteWithResult:(FBSDKLoginManagerLoginResult *)result error:(NSError *)error {
if (error) {

} else if (result.isCancelled) {

} else {
    //I want get user info here and set values to properties.
    self.userName =
    self.userImage =
    self.userEmail = 

 }
}

如果您知道其他解决方案,请告诉我。

【问题讨论】:

标签: ios facebook


【解决方案1】:

试试这个

FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
    [login logInWithReadPermissions:@[@"email",@"user_photos"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
    if ([result.grantedPermissions containsObject:@"email"]) {
       [self fetchData]

    } 
}];

在 fetchData 方法中

- (void)fetchData {

[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil]
 startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {

     if (!error) {

         DLog(@"fetched user:%@", result);

         self.userFirstName = [result objectForKey:@"first_name"];
         self.userLastName = [result objectForKey:@"last_name"];
         self.userEmail = [result objectForKey:@"email"];
         NSString *facebookId = [result objectForKey:@"id"];

         self.userProfileImage = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large", facebookId];
         DLog(@"URL=%@",self.userProfileImage);

       }
   }];
 }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-24
    • 2016-10-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多