0
votes

I am trying to implement a Facebook social login through using Firebase, and I think I'm almost finished with it, but somehow the console is telling me that the user is cancelling for some reason.

One point, the code was just not working and printed that the Facebook sign in failed, but I changed the parameter in acebookLogin.logInWithReadPermissions from "email" to "email", "public_profile", "user_friends", which lead to the next error line.

Here's the method that tries to call Facebook login.

Future<FirebaseUser> startFacebookLogin() async {
    var facebookLogin = new FacebookLogin();
    final result = await facebookLogin.logInWithReadPermissions(["email", "public_profile", "user_friends"]);
    FacebookAccessToken myToken = result.accessToken;
    switch (result.status) {
      case FacebookLoginStatus.loggedIn:
        AuthCredential credential = FacebookAuthProvider.getCredential(
            accessToken: myToken.token);
        FirebaseUser facebookUser = await FirebaseAuth.instance
            .signInWithCredential(credential);
        return facebookUser;
        break;
      case FacebookLoginStatus.cancelledByUser:
        print("Facebook sign in cancelled by user");
        break;
      case FacebookLoginStatus.error:
        print("Facebook sign in failed");
        break;
    }
  }

and this IconButton activates the social login when it's pressed.

IconButton(
   onPressed: () => startFacebookLogin().then((FirebaseUser user) => 
              print(user)).catchError((e) => print(e)),
   icon: new Icon(const IconData(0xe900, fontFamily: 'facebook')),
         color: Colors.blue,
)

Not quite sure what would be causing the cancelledByUser case.

1
bro did you get the answer for this? - myname

1 Answers

0
votes

Does that happen with Test Users too?

I'm wondering if it could be the case that your app has status In Development with Facebook and you're trying to test the login with a different account to the one the app is registered under.