我将我的 iOS 代码迁移到 FBSDK v4 + Parse 1.7.1,我正在尝试处理将用户链接到 FB ID 但它已经链接的情况:
Another user is already linked to this facebook id. (Code: 208, Version: 1.7.1)
用户注销和 FB 登录后一切似乎都正常,但每次我更改或保存当前用户,或查询表时,我都会收到各种错误,例如:
Parse::UserCannotBeAlteredWithoutSessionError (Code: 206, Version: 1.7.1)
"PFKeychainStore" failed to set object for key 'currentUser'
no results matched the query (Code: 101, Version: 1.7.1)
这是我的代码:
NSArray *permisions = [NSArray arrayWithObjects:@"public_profile", @"email", @"user_friends", nil];
[PFFacebookUtils linkUserInBackground:[PFUser currentUser] withReadPermissions:permissions block:^(BOOL succeeded, NSError *error) {
if(succeeded && !error) {
//... use data
}
else {
if(error.code == 208) {
[PFUser logOut];
[PFFacebookUtils logInInBackgroundWithReadPermissions:permissions block:^(PFUser *user, NSError *error) {
//here I get a valid user and no error but...
//after this point the errors mentioned start to show up
}
}
else
//... handle other errors
}
}];
我使用 Parse 的自动用户,直到用户链接到 FB 帐户。
希望得到一些帮助,谢谢!
最佳答案
添加 becomeInBackground 停止了错误:
NSArray *permisions = [NSArray arrayWithObjects:@"public_profile", @"email", @"user_friends", nil];
[PFFacebookUtils linkUserInBackground:[PFUser currentUser] withReadPermissions:permissions block:^(BOOL succeeded, NSError *error) {
if(succeeded && !error) {
//... success
}
else {
if(error.code == kPFErrorFacebookAccountAlreadyLinked) {
[PFUser logOutInBackgroundWithBlock:^(NSError *error) {
if(!error) {
[PFFacebookUtils linkUserInBackground:[PFUser currentUser] withReadPermissions:permissions block:^(BOOL succeeded, NSError *error) {
[PFUser becomeInBackground:[[PFUser currentUser] sessionToken] block:^(PFUser *user, NSError *error) {
if(user && !error) {
// ... success
}
else {
//... handle become error
}
}];
}];
}
else {
// ... handle bad logout
}
}
else {
//... handle other errors
}
}
}];
关于ios - PFUser logOut 和 PFFacebookUtils logInInBackgroundWithReadPermissions 后的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29723218/