解析Facebook登录集成处理无效会话

时间:2017-01-19 18:47:07

标签: swift facebook-graph-api parse-platform facebook-login parse-server

我想知道是否有人知道swift3中的更新代码以获取以下内容。我从Parse Server github(下面的链接)得到了这个。

FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
    // handle successful response
} else if ([[error userInfo][@"error"][@"type"] isEqualToString: @"OAuthException"]) { // Since the request failed, we can check if it was due to an invalid session
    NSLog(@"The facebook session was invalidated");
    [PFFacebookUtils unlinkUserInBackground:[PFUser currentUser]];
} else {
    NSLog(@"Some other error: %@", error);
}

}];

具体来说,我想了解在

中检查的内容
"[[error userInfo][@"error"][@"type"] isEqualToString: @"OAuthException"]". 

我理解swift3是否要将其设置为

"if error = (error as? NSError!).userInfo[something]"

但是我不确定我需要在userinfo []中传递哪个参数。例如。 FBSDKGraphRequestErrorCategoryKey,FBSDKGraphRequestErrorGraphError等。

https://github.com/ParsePlatform/ParseUI-iOS/wiki/Integrate-Login-with-Facebook

1 个答案:

答案 0 :(得分:0)

API将在JSON正文中返回HTTP 400状态代码,代码和子代码,以解释错误的性质。在你的情况下无效的会话。只需将其转换为变量并检查它是否等于"OAuthException"

{
      "error": {
        "message": "Error validating access token: The session is invalid 
                    because the user logged out.", 
        "type": "OAuthException", 
        "code": 190
      }
    }