我想知道是否有人知道 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
最佳答案
API 将返回 HTTP 400 状态代码、JSON 正文中的代码和子代码,解释错误的性质。在您的情况下, session 无效。只需将其转换为变量并检查它是否等于 "OAuthException"
。
{
"error": {
"message": "Error validating access token: The session is invalid
because the user logged out.",
"type": "OAuthException",
"code": 190
}
}
关于swift - 解析 Facebook 登录集成处理无效 session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41749439/