web-dev-qa-db-ja.com

(com.facebook.sdk.loginエラー304。)FBSDK 4.2のエラー

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");

                 }
             }
         }];
    }
16
Hassan Aftab

私がやっていたようです

[FBSDKAccessToken refreshCurrentAccessToken:^(FBSDKGraphRequestConnection *connection, id result, NSError *error){}

ログイン操作中のバックグラウンドスレッド。私はそれを削除し、それは完全にうまくいきました。

5
Hassan Aftab

これは、以前のログイントークンがクリアされていないことが原因である可能性があります。ログインする前に、ログアウトしてください。

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");
                                        }
                                   }
                               }];
39
Minal Soni

Swift 4の更新:

このようなことをするたびに

    FBSDKLoginManager().login(withReadPermission: ["email"], from: self) { (result, error) in  // Check for error and then login }
    //insert this code before the **Login code:** 
    FBSDKLoginManager().logOut()

そしてそれはうまくいくはずです:)

17
Sanket Ray

次のように、ログインAPIの直前にログインを実行しているアクションでfbloginマネージャーをログアウトします。

fbLoginManager.logOut()
fbLoginManager.logIn(withReadPermissions: ["public_profile","email"], from: self) { (result, error) -> Void in 
    //Your code here
}
4
Sandeep Yadav

これを試してみてください。ただし、Swift 2"ログインボタンアクションでのログイン前のログアウト"ログインを許可:FBSDKLoginManager = FBSDKLoginManager()ログイン。ログアウト()

1
Bhushan Gawande

Swift 5アップデート
まず、accessTokenを更新するか、ログアウトしてください。

func loginButtonClicked() {
            let loginManager = LoginManager()
            loginManager.logOut()
            loginManager.logIn(permissions: [.email], viewController: nil) { (loginResult) in
                switch loginResult {
                case .success(let grantedPermissions, _, let token):
                    self.returnUserData()
                    print("Success",token,grantedPermissions)
                    break
                case .cancelled:

                    print("Cancel")
                    break
                case .failed(let error):

                    print(error.localizedDescription)
                    break
                }
            }


        }
1