iOS Parse Facebook Login error 308 FBSDKLoginBadChallengeString

后端 未结 21 2445
小鲜肉
小鲜肉 2020-12-13 17:18

I\'m trying to implement Facebook login in my iOS app, using Parse.

let permissionsArray = [\"public_profile\", \"email\"]

PFFacebookUtils.logInInBackgroun         


        
21条回答
  •  佛祖请我去吃肉
    2020-12-13 18:09

    I got the same problem when I was trying to catch login and logout event as below

    loginButton = [[FBSDKLoginButton alloc] init];
    // Handle clicks on the button
    [loginButton
     addTarget:self
     action:@selector(loginButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    
    // Once the button is clicked, show the login dialog
    -(void)loginButtonClicked
    {
      FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
      [login
        logInWithReadPermissions: @[@"public_profile"]
              fromViewController:self
                         handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
        if (error) { 
          NSLog(@"Process error");
        } else if (result.isCancelled) {
          NSLog(@"Cancelled");
        } else {
          NSLog(@"Logged in");
        }
      }];
    }
    

    But this is only good for a custom login button, if you are using default fb login button, the FBSDKLoginManager has been initialized already, you will get the error when trying to create another one.

    So, in order to catch login and logout event, just set the delegate for login button and then handle it like the following:

        loginButton = [[FBSDKLoginButton alloc] init];
        loginButton.delegate = self;
    
    
    - (void)loginButton:(FBSDKLoginButton *)loginButton didCompleteWithResult:(FBSDKLoginManagerLoginResult *)result error:(NSError *)error {
        if (!error) {
            [self getFBProfile];
        }
    }
    
    - (void)loginButtonDidLogOut:(FBSDKLoginButton *)loginButton {
        [self logout];
    }
    

提交回复
热议问题