2015-11-04 39 views
0

这里是我的代码,我只获取用户的用户名和facebook标识。如何在ios 9中使用facebook sdk 4.7获取用户的电子邮件ID

FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init]; 
    [login 
    logInWithReadPermissions: @[@"public_profile",@"email",@"user_friends"] 
    fromViewController:self 
    handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) { 
     if (error) { 
      NSLog(@"Process error"); 
     } else if (result.isCancelled) { 
      NSLog(@"Cancelled"); 
     } else { 

      if ([FBSDKAccessToken currentAccessToken]) { 
       [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil] 
        startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { 
         if (!error) { 
          NSLog(@"fetched user:%@", result); 
         } 
        }]; 
      }    NSLog(@"Results=%@",result); 
      NSLog(@"Logged in"); 
     } 
    }]; 

,它也给一些像这样的错误 -

-canOpenURL: failed for URL: "fbauth2:/" - error: "(null)" -canOpenURL: failed for URL: "fbauth2:/" - error: "(null)"

FBSDKLog: starting with Graph API v2.4, GET requests for /me should contain an explicit "fields" parameter

回答

6

我使用的吊舱Facebook的SDK,它的工作在iOS9.0和Xcode 7.1。试试这个代码

void (^sendRequestsBlock)(void) = ^{ 

    FBSDKGraphRequest *postRequest = nil; 
    NSDictionary *parameters = [NSDictionary dictionaryWithObject:@"id,email,first_name,last_name,name,picture{url}" forKey:@"fields"]; 

    postRequest = [[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:parameters HTTPMethod:@"GET"]; 
    [postRequest startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) 
    { 
     if (!error) { 
      NSDictionary *dictResult = (NSDictionary *)result; 

     } 
    }]; 
}; 

/// login start 
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init]; 
[login logOut]; 
NSArray *permissions = [NSArray arrayWithObjects:@"email",@"public_profile", nil]; 

[login logInWithReadPermissions:permissions fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) { 
    if (error) { 

    } else if (result.isCancelled) { 

    } else { 

     if ([result.grantedPermissions containsObject:@"email"]) { 

      sendRequestsBlock(); 

     } 
    } 
}] 
+0

我在哪里写sendRequestBlock在我的班? –

+0

谢谢,keyur它的工作 –

+0

我越来越result.isCancelled = true,我能做些什么? –

相关问题