0

这是我的代码,我只获取用户的用户名和 facebook 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:URL 失败:“fbauth2:/” - 错误:“(null)” -canOpenURL:URL 失败:“fbauth2:/” - 错误:“(null)”

FBSDKLog:从 Graph API v2.4 开始,对 /me 的 GET 请求应包含显式的“字段”参数

4

1 回答 1

6

我正在为 Facebook sdk 使用 pod,它在 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();

        }
    }
}]
于 2015-11-04T04:26:55.147 回答