调用FBRequest:requestForMe:返回nil结果

时间:2013-12-08 22:21:07

标签: ios facebook facebook-graph-api facebook-ios-sdk

我正在尝试调用FBRequest:requestForMe:startWithCompletionHandler并且无法让它在我自己的代码中工作所以尝试将它添加到示例项目SessionLoginSample但是仍然得到相同的结果,结果是nil

我已经在示例项目中添加了updateView方法,但它放置的位置没有区别,id始终为nil:

- (void)updateView {
    // get the app delegate, so that we can reference the session property
    SLAppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
    if (appDelegate.session.isOpen) {
        // valid account UI is shown whenever the session is open
        [self.buttonLoginLogout setTitle:@"Log out" forState:UIControlStateNormal];
        [self.textNoteOrLink setText:[NSString stringWithFormat:@"https://graph.facebook.com/me/friends?access_token=%@",
                                 appDelegate.session.accessTokenData.accessToken]];

        FBRequest *me = [FBRequest requestForMe];
        [me startWithCompletionHandler:^(FBRequestConnection *connection,
                                         id result,
                                         NSError *error) {
            NSDictionary<FBGraphUser> *my = (NSDictionary<FBGraphUser> *) result;
            NSLog(@"My dictionary: %@", my.first_name);
        }];


    } else {
        // login-needed account UI is shown whenever the session is closed
        [self.buttonLoginLogout setTitle:@"Log in" forState:UIControlStateNormal];
        [self.textNoteOrLink setText:@"Login to create a link to fetch account data"];
    }
}

NSError包含domain:com.facebook.sdk代码:5。

经过一些谷歌搜索和实验后,我通过在它之前添加对[FBSession setActiveSession:appDelegate.session]的调用来使requestForMe工作,但是我无法将这个工作代码传输到我自己的项目中,在那里我得到相同的错误代码5,但我看不出我的项目代码与示例项目的代码有什么不同。

1 个答案:

答案 0 :(得分:0)

经过大量的Google搜索后,我设法通过在调用requestForMe之前添加以下行来解决此问题

[FBSession setActiveSession:appDelegate.session];