Flutter_facebook_login: how to get email, first_name, last_name?

Created on 21 Mar 2018  ·  16Comments  ·  Source: roughike/flutter_facebook_login

Hi Liro, is there any way to get those fields on the login? thanks

enhancement

Most helpful comment

Update: I have no plans of doing it currently.

Anyway, here's sample code for doing it.

var result = await facebookSignIn.logInWithReadPermissions(['email']);
var accessToken = result.accessToken;
var graphResponse = await http.get(
            'https://graph.facebook.com/v2.12/me?fields=name,first_name,last_name,email&access_token=${accessToken.token}');
var profile = JSON.decode(graphResponse.body);

Now profile contains something like this:

{
   "name": "Iiro Krankka",
   "first_name": "Iiro",
   "last_name": "Krankka",
   "email": "iiro.krankka\u0040gmail.com",
   "id": "<user id here>"
}

Closing this one, but thanks for the suggestion!

All 16 comments

I can look into this later this week, but cannot promise anything for now. Also, I'm not sure if it's in the scope of this plugin: the name is flutter_facebook_login, and that's the thing it does.. :)

If you're in a rush, you can already do it today.

  1. Get the access token for the user using this plugin.
  2. Make a standard HTTP Graph request according to the Facebook documentation to retrieve the user profile. Use the token you get by using this plugin to authenticate.

Thanks!

Update: I have no plans of doing it currently.

Anyway, here's sample code for doing it.

var result = await facebookSignIn.logInWithReadPermissions(['email']);
var accessToken = result.accessToken;
var graphResponse = await http.get(
            'https://graph.facebook.com/v2.12/me?fields=name,first_name,last_name,email&access_token=${accessToken.token}');
var profile = JSON.decode(graphResponse.body);

Now profile contains something like this:

{
   "name": "Iiro Krankka",
   "first_name": "Iiro",
   "last_name": "Krankka",
   "email": "iiro.krankka\u0040gmail.com",
   "id": "<user id here>"
}

Closing this one, but thanks for the suggestion!

Ok, thanks!

I recommended adding this to readme or the document. 👍

BTW: It's good to implement built-in getting profile info API.

Adding public_profile worked for me, I got back all the pertinent details.

final FacebookLoginResult facebookLoginResult = await _facebookLogin
          .logInWithReadPermissions(['email', 'public_profile']);
final FacebookLoginResult facebookLoginResult = await _facebookLogin
          .logInWithReadPermissions(['email', 'public_profile']);

what do you mean i only got status and token using this

Adding public_profile worked for me, I got back all the pertinent details.

final FacebookLoginResult facebookLoginResult = await _facebookLogin
          .logInWithReadPermissions(['email', 'public_profile']);

Can you get the user's name?

Cannot request for graph API scopes #199
Could someone look into this?

can i also get profile picture URL?

Yes, @shakilur157 you can,

Take a look here:

thanks for the reply @MisterioRee

I have a problem with facebook login on android

var login = FacebookLogin ();
     login.loginBehavior = FacebookLoginBehavior.webViewOnly;
     final result = await login.logIn (['email']);

in the third line close the app

Failed to send request: {"jsonrpc": "2.0", "id": "210", "method": "resume", "params": {"isolateId": "isolates / 637907629644467"}}

I perfectly followed in the footsteps of https://pub.dev/packages/flutter_facebook_login#-readme-tab-

please help

this was my working code

static final FacebookLogin facebookSignIn = new FacebookLogin();

String _message = 'Log in/out by pressing the buttons below.';

Future _login() async {
final FacebookLoginResult result =
await facebookSignIn.logIn(['email']);

switch (result.status) {
  case FacebookLoginStatus.loggedIn:
    final FacebookAccessToken accessToken = result.accessToken;
    _showMessage('''
     Logged in!

     Token: ${accessToken.token}
     User id: ${accessToken.userId}
     Expires: ${accessToken.expires}
     Permissions: ${accessToken.permissions}
     Declined permissions: ${accessToken.declinedPermissions}
     ''');

// Navigator.popUntil(context,
ModalRoute.withName(Navigator.defaultRouteName));

    var graphResponse = await http.get(
        '

https://graph.facebook.com/v2.12/me?fields=name,first_name,last_name,email&access_token=${accessToken.token}'
);
var profile = json.decode(graphResponse.body);
print('response : ${profile}');

    SingletonService saveData = new SingletonService();
    saveData.appUserDisplayName = profile['name'];
    saveData.appUserID = accessToken.userId;
    saveData.appUserProfilePictureURL = "https://graph.facebook.com/" +

accessToken.userId + "/picture?height=200";
saveData.appUserEmailID = profile['email'];

    saveData.signInMethod = "Facebook";
    Navigator.of(context).pushReplacementNamed(
      '/Profile',
      arguments: 'Hello there from the first page!',
    );
    break;
  case FacebookLoginStatus.cancelledByUser:
    _showMessage('Login cancelled by the user.');
    break;
  case FacebookLoginStatus.error:
    _showMessage('Something went wrong with the login process.\n'
        'Here\'s the error Facebook gave us: ${result.errorMessage}');
    break;
}

}

On Fri, Mar 20, 2020 at 8:34 PM gauchok notifications@github.com wrote:

I have a problem with facebook login on android

var login = FacebookLogin ();
login.loginBehavior = FacebookLoginBehavior.webViewOnly;
final result = await login.logIn (['email']);

in the third line close the app

Failed to send request: {"jsonrpc": "2.0", "id": "210", "method":
"resume", "params": {"isolateId": "isolates / 637907629644467"}}

please help


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/roughike/flutter_facebook_login/issues/11#issuecomment-601732011,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AJDIOSVDNIRA2LJEIXPZTE3RIN5HJANCNFSM4EWNQIXA
.

Help! No Funciona .logInWithReadPermissions(['email', 'public_profile']); en su lugar eh puesto .logIn(['email', 'public_profile']); pero no funciona, alguna idea de como utilizar esa nueva función de AndroidX

'public_profile'

Is it reliable for version 3.0.0 too?

Was this page helpful?
0 / 5 - 0 ratings