Получить информацию о пользователе Facebook с помощью моего собственного UIButton

Я пытаюсь создать кнопку подключения к Facebook, и мне нужно получить для этого FBGraphUser, когда я подключен. У меня есть следующий код на моей кнопке:

-(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:

    Error: HTTP status code: 400
    FBSDKLog: Response  :
    The operation couldn’t be completed. (com.facebook.sdk error 5.)
    (null)
    error: Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed.                   
    (com.facebook.sdk error 5.)" UserInfo=0x925f760 {com.facebook.sdk:ParsedJSONResponseKey=
    {type = mutable dict, count = 2,
     entries =>
      1 : {contents = "code"} =  
      {value = +400, type = kCFNumberSInt32Type}
      2 : {contents = "body"} = {type = mutable dict, count = 1,
       entries =>
       11 : {contents = "error"} = {type = mutable dict, count = 3,
       entries =>
    2 : {contents = "type"} = {contents = "OAuthException"}
        3 : {contents = "message"} = {contents = "An active access token must be used to query information about         
       the current user."}
    6 : {contents = "code"} = 2500

Я что-то упускаю?


person Loadex    schedule 18.10.2012    source источник


Ответы (1)


По-видимому, FBRequestConnection использует переменную в FBSession, называемую активной сессией, чтобы заставить ее работать сразу после

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

ставить :

FBSession.activeSession = session;
person Loadex    schedule 19.10.2012