在iOS中使用FBSDKGraphRequest获取错误以检索用户的电子邮件ID

时间:2015-05-23 15:25:28

标签: ios facebook-sdk-4.0

在我的应用程序中,我试图通过使用FaceBookSDK V4将Facebook与登录集成,在这里我成功登录并尝试获取用户的电子邮件我正在获取错误。在viewDidLoad中我放了以下代码:

  FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init];
        loginButton.frame=CGRectMake(50,100,500,50);
        loginButton.readPermissions=@[@"email"];
        [self.view addSubview:loginButton];


        [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil]
         startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
             if (!error)
             {
                 NSLog(@"fetched user:%@  and Email : %@", result,result[@"email"]);
             }
             else{
                 NSLog(@"Error %@",error);
             }
         }];

最后我得到以下错误:

Error Domain=com.facebook.sdk.core Code=8 "The operation couldn’t be completed. (com.facebook.sdk.core error 8.)" UserInfo=0x15d9b570 {com.facebook.sdk:FBSDKGraphRequestErrorGraphErrorCode=2500, com.facebook.sdk:FBSDKGraphRequestErrorParsedJSONResponseKey={
    body =     {
        error =         {
            code = 2500;
            message = "An active access token must be used to query information about the current user.";
            type = OAuthException;
        };
    };
    code = 400;
}, com.facebook.sdk:FBSDKGraphRequestErrorHTTPStatusCodeKey=400, com.facebook.sdk:FBSDKErrorDeveloperMessageKey=An active access token must be used to query information about the current user., com.facebook.sdk:FBSDKGraphRequestErrorCategoryKey=0}

1 个答案:

答案 0 :(得分:0)

如果您正在使用Parse,则需要使用ParseFacebookUtilsV4切换ParseFacebookUtils并相应地更新。常规ParseFacebookUtils不适用于FB SDK V4,最终会出现非常神秘的错误和随机运行时故障(例如难以捉摸的错误代码8)。