2012-10-18 2 views
2

페이스 북 연결 버튼을 만들려고하는데 연결되었을 때이 FBGraphUser를 받아야합니다. 내 버튼에 다음 코드를 :내 UIButton으로 사용자 Facebook 정보 얻기

 
    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 

나는 실종 뭔가 :

-(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를 호출 할 때 실패한다는 것입니다?

답변

4

Aparently의 FBRequestConnection가 작동하도록 FBSession의 변수를 활성 세션라는 사용 직후

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

넣어 :

FBSession.activeSession = session; 
관련 문제