(com.facebook.sdk.login错误304.)FBSDK 4.2出错

Has*_*tab 16 facebook objective-c ios facebook-login

我正在尝试使用Facebook功能实现登录,但我收到了以下错误.

登录失败,错误:无法完成操作.(com.facebook.sdk.login错误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");

                 }
             }
         }];
    }
Run Code Online (Sandbox Code Playgroud)

Min*_*oni 38

这可能是因为以前的登录令牌没有被清除.所以在登录之前只需注销.

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");
                                        }
                                   }
                               }];
Run Code Online (Sandbox Code Playgroud)


San*_*Ray 17

Swift 4更新:

每次你执行这样的事情 __CODE__登录代码 之前插入这个代码:__CODE__ 它应该工作正常:)


Has*_*tab 5

我好像在做

[FBSDKAccessToken refreshCurrentAccessToken:^(FBSDKGraphRequestConnection *connection, id result, NSError *error){}
Run Code Online (Sandbox Code Playgroud)

在登录操作期间的后台线程中.我删除了它,它工作得非常好.


小智 5

在登录 api 之前执行登录操作时注销 fblogin 管理器,例如:-

fbLoginManager.logOut()
fbLoginManager.logIn(withReadPermissions: ["public_profile","email"], from: self) { (result, error) -> Void in 
    //Your code here
}
Run Code Online (Sandbox Code Playgroud)