为什么我不能在ios中重新打开会话后访问facebook好友列表

时间:2012-11-20 22:35:01

标签: objective-c ios xcode facebook facebook-graph-api

我正在升级到ios的facebook 3.0 sdk。事情进展顺利,直到我重新启动应用程序后尝试打开现有会话。我正在尝试访问facebook用户的朋友列表。

if ([[FBSession activeSession] isOpen]) {
    [request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
        //do something here
    }];
}else{
    [[self session] openWithCompletionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
        if ([self isValid]) {
            [request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                //log this error we always get
                NSLog(@"%@",error);
                //do something else
            }];
        }
    }];
}

但是我收到了这个错误:

Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0x1d92ff40 {com.facebook.sdk:ParsedJSONResponseKey={
  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:HTTPStatusCode=400}

我发现如果我使用FBSession重新授权方法,它允许我毫无错误地完成请求,但这也意味着我必须在每次重新启动应用程序时显示UI或切换应用程序,这是不可接受的。关于我应该采取哪些不同的建议?

1 个答案:

答案 0 :(得分:3)

登录后我没有在请求上设置会话。简单的错误。

[[self session] openWithCompletionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
    if ([self isValid]) {
        //I should have been doing this
        request.session = [FBSession activeSession];
        [request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
            //log this error we always get
            NSLog(@"%@",error);
            //do something else
        }];
    }
}];