Search code examples
firebaseflutterfacebook-graph-api

Facebook login returns generic profile picture URL


Well I'm using the code from Firebase and the in the user object the photoURL which being returned is General facebook profile with no image

which is generic profile picture

Future signInWithFacebook() async {
try {
  // Trigger the sign-in flow
  final  result = await FacebookAuth.instance.login();

  // Create a credential from the access token
  final FacebookAuthCredential facebookAuthCredential =
  FacebookAuthProvider.credential(result.token);

  // Once signed in, return the UserCredential
  UserCredential res = await FirebaseAuth.instance.signInWithCredential(facebookAuthCredential);
  User user = res.user;
  //create a new document for the user with the uid
  await UserProfileDatabaseService(uid: user.uid).updateUserData(
      user.displayName,
      user.email,
      user.emailVerified,
      user.phoneNumber,
      user.isAnonymous
      , {'helper': true},
      250
  );      return user;
} catch (e) {
  print(e.toString());
  return null;
}

}

Solution

  • you can use the following code to display the Facebook profile picture URL after a successful login:

    await FacebookAuth.instance.login();
    final user = await FacebookAuth.instance.getUserData();
    Image.network(user["picture"]['data']['url']);
    

    This code logs the user in via FacebookAuth, retrieves their user data, and displays their profile picture using the Image.network widget.