在ios9中退出应用程序后获取facebook friendlist的问题

时间:2016-07-20 10:00:06

标签: ios objective-c iphone facebook-graph-api fbconnect

我为fblogin编写了以下代码:

 FBSDKLoginManager *fblogin = [[FBSDKLoginManager alloc] init];
    [fblogin logInWithReadPermissions:params fromViewController:viewController handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
    {
        if (error) {
            // Show process error from facebook
            NSLog(@"Process error");
            completion(nil,error);
        } else if (result.isCancelled) {
            /// At time of done and cancel event
            NSLog(@"Cancelled");
            completion(nil,error);
        } else {
            /// This action come at least one permission allowed user
            NSLog(@"Logged in");
            completion(result,error);
        }
    }];

获取用户详细信息我写的代码是:

[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"picture.type(large), email,birthday,name,gender,first_name, last_name,bio, invitable_friends"}] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error)
    {

              if(!error)
        {
            completion(result,error);
        }
        else
        {
            completion(nil,error);
        }
    }];

用户登录后。我正在尝试获取好友列表(仅当用户点击邀请朋友按钮。

要获取好友列表,我用来获取好友列表的代码:

   FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                                  initWithGraphPath:@"/me/invitable_friends?limit=5000"
                                  parameters:@{@"fields": @"name,first_name, last_name,invitable_friends"}
                                  HTTPMethod:@"GET"];
    [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                          id result,
                                          NSError *error) {
        // Handle the result
        NSLog(@"result==>%@",result);
    }];

我从上面的代码中得到了正确的朋友列表。 问题是,当我退出我的应用程序并重新打开应用程序然后尝试再次获取好友列表时,它会给我错误。

我得到的错误是:

Error Domain=com.facebook.sdk.core Code=8 "(null)" UserInfo={com.facebook.sdk:FBSDKGraphRequestErrorCategoryKey=0, com.facebook.sdk:FBSDKGraphRequestErrorHTTPStatusCodeKey=400, com.facebook.sdk:FBSDKErrorDeveloperMessageKey=An active access token must be used to query information about the current user., com.facebook.sdk:FBSDKGraphRequestErrorGraphErrorCode=2500, com.facebook.sdk:FBSDKGraphRequestErrorParsedJSONResponseKey={
    body =     {
        error =         {
            code = 2500;
            "fbtrace_id" = BrC8am8ChZ6;
            message = "An active access token must be used to query information about the current user.";
            type = OAuthException;
        };
    };
    code = 400;
}}

1 个答案:

答案 0 :(得分:0)

我通过在我的appdelegate中编写以下行解决了这个问题:

[[FBSDKApplicationDelegate sharedInstance]应用程序:application didFinishLaunchingWithOptions:launchOptions];

我从以下链接得到了这个答案:Reliable check for active session on app startup in Facebook iOS SDK v4.0

谢谢你