Email is getting null after login with facebook in flutter

Viewed 315

I am trying to facebook signin by using this library flutter_facebook_auth. I followed all the necessary steps to add the code in android and ios based on the documentation of that library. When i try to signin i get all the data like name, photo etc but email i am getting null. I tried with multiple facebook account but still user email i am getting null. What is the reason email is not showing? Below is the code of facebook signin

  Future<UserCredential> signInWithFacebook() async {
    // Trigger the sign-in flow
    final LoginResult loginResult = await FacebookAuth.instance.login();

    // Create a credential from the access token
    final OAuthCredential facebookAuthCredential =
        FacebookAuthProvider.credential(loginResult.accessToken!.token);
    final userData = await FacebookAuth.instance.getUserData();
    print(userData);
    // Once signed in, return the UserCredential
    return FirebaseAuth.instance.signInWithCredential(facebookAuthCredential);
  }
0 Answers
Related