2

我正在尝试创建一个 Facebook 连接按钮,当我连接时我需要为此获取 FBGraphUser。我的 Button 上有以下代码:

-(IBAction)fbButtonClickHandler:(id)sender {
    mainDelegate = (AppDelegate*)[[UIApplication sharedApplication]delegate];

  if (mainDelegate.fbSession.isOpen) { 
    [mainDelegate.fbSession closeAndClearTokenInformation]; // FB delog
  }
  else {
    if (mainDelegate.fbSession.state != FBSessionStateCreated) {
        mainDelegate.fbSession = [[FBSession alloc] initWithPermissions:[NSArray arrayWithObjects:@"email", @"publish_actions", @"user_birthday",nil]];
    }
     // loggin on facebook
    [mainDelegate.fbSession openWithCompletionHandler:^(FBSession *session,
                                                     FBSessionState status,
                                                     NSError *error) {

        [fbButton setTitle:[self updateFbButtonLabel] forState:UIControlStateNormal];
        // reading the documentation i'm trying this to get the FBGraphUser
        if(session.isOpen) {
            [FBRequestConnection startForMeWithCompletionHandler:^(FBRequestConnection *connection, id<FBGraphUser> user, NSError *error) {

                  if (!error) {
                    NSString *userInfo = @"";

                    // Example: typed access (name)
                    // - no special permissions required
                    userInfo = [userInfo
                                stringByAppendingString:
                                [NSString stringWithFormat:@"Name: %@\n\n",
                                 user.name]];

                    // Example: typed access, (birthday)
                    // - requires user_birthday permission
                    userInfo = [userInfo
                                stringByAppendingString:
                                [NSString stringWithFormat:@"Birthday: %@\n\n",
                                 user.birthday]];
                    // Display the user info
                    NSLog(@"%@", userInfo);
                  }
                  NSLog(@" error: %@" , error);
                }];
        }
       }
    }];
}
}

问题是当我打电话时它失败了startForMeWithCompletionHandler

    错误:HTTP 状态码:400
    FBSDKLog:响应:
    操作无法完成。(com.facebook.sdk 错误 5。)
    (空值)
    错误:错误域=com.facebook.sdk 代码=5“操作无法完成。                   
    (com.facebook.sdk 错误 5。)“UserInfo=0x925f760 {com.facebook.sdk:ParsedJSONResponseKey=
    {type = 可变字典,count = 2,
     条目 =>
      1:{内容=“代码”}=  
      {值 = +400,类型 = kCFNumberSInt32Type}
      2 : {contents = "body"} = {type = mutable dict, count = 1,
       条目 =>
       11 : {contents = "error"} = {type = mutable dict, count = 3,
       条目 =>
    2 : {contents = "type"} = {contents = "OAuthException"}
        3 : {contents = "message"} = {contents = "必须使用活动访问令牌来查询有关信息         
       当前用户。"}
    6 : {内容 = "代码"} = 2500

我错过了什么吗?

4

1 回答 1

4

显然, FBRequestConnection 在 FBSession 中使用了一个名为 active session 的变量来使其在之后工作

 [mainDelegate.fbSession openWithCompletionHandler:^(FBSession *session,
                                                     FBSessionState status,
                                                     NSError *error) {

放 :

FBSession.activeSession = session;
于 2012-10-19T09:14:17.983 回答