2

if i'm trying to login with another account then i didn't get user information.

void initiateFacebookLogin() async {
    var facebookLoginResult = await facebookLogin
        .logInWithReadPermissions(['email', 'public_profile']);

    switch (facebookLoginResult.status) {
      case FacebookLoginStatus.error:
        _fblogin.sink.add(FacebookLoginData(false, ""));
        break;
      case FacebookLoginStatus.cancelledByUser:
        _fblogin.sink.add(FacebookLoginData(false, ""));
        break;
      case FacebookLoginStatus.loggedIn:
        var graphResponse = await http.get(
            'https://graph.facebook.com/v2.12/me?fields=name,first_name,last_name,email&access_token=${facebookLoginResult.accessToken.token}');

        var profile = json.decode(graphResponse.body);
        _fblogin.sink.add(FacebookLoginData(true, profile));
        break;
    }
  }

in iOS device error message :

iOS - Error Domain=com.facebook.sdk.login Code=304 "(null)" in android device error message user login with different account.

questionasker
  • 2,536
  • 12
  • 55
  • 119
Parth Bhanderi
  • 2,378
  • 3
  • 15
  • 30

1 Answers1

1

The first thing that needs to be done inside that method in order to make it work 100% of the time (it would fail when the user changes accounts or the access token gets refreshed):

await FacebookAuth.instance.logOut();
PaianuVlad23
  • 1,751
  • 2
  • 13
  • 16