我正在尝试使用Facebook功能实现登录,但是我正在收到以下错误.
Login Failed with error: The operation Couldn’t be completed.
(com.facebook.sdk.login error 304.)
这是我的代码
- (void)loginWithFacebook {
Nsstring *const read_actions = @"email";
[[[FBSDKLoginManager alloc] init]
logInWithReadPermissions:@[read_actions] handler:^(FBSDKLoginManagerLoginResult *result,NSError *error)
{
if (error) {
NSLog(@"Login Failed with error: %@",error.localizedDescription);
}
else if (result.isCancelled)
{
NSLog(@"Login Failed due to Cancel");
}
else
{
if ([result.grantedPermissions containsObject:read_actions]) {
NSLog(@"Permission granted");
}
}
}];
}
解决方法
这可能是因为之前登录的令牌不会被清除.
Nsstring *const read_actions = @"email";
FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
[loginManager logout];
[loginManager logInWithReadPermissions:@[read_actions]
handler:^(FBSDKLoginManagerLoginResult *result,NSError *error) {
if (error) {
NSLog(@"Login Failed with error: %@",error.localizedDescription);
}
else if (result.isCancelled) {
NSLog(@"Login Failed due to Cancel");
} else {
if ([result.grantedPermissions containsObject:read_actions]) {
NSLog(@"Permission granted");
}
}
}];