Search code examples
facebookfacebook-graph-apifederated-identity

Facebook GraphQL - How to get a users email address and name from backend


I have an app where the user logs into Facebook (and thus has an Auth Token) and then sends that token to my server for authentication within the app.

If it's the users first time in the app, I need to sign them up as well (gather email and name)

Using the users FB auth token (and any server-side tokens) how do I retrieve the user's email address and name? (What endpoints do I need to hit with what tokens/body?)

--

Additional Info:

  • The login is scoped with ['public_profile', 'email']
  • The application is running in Node.js on AWS Lambda, and I'd prefer to make a simple fetch if possible instead of installing a whole gql client.
  • I have tried looking at their graphQL documentation, but I can't seem to make heads or tails out of it.
  • I do have access to the user's ID (example: 10157426730xxxxxx)

Solution

  • This would be the API call to get the name and email of a user, with a User Token:

    https://graph.facebook.com/me?fields=name,email&access_token=xxxx

    Alternatively, you can add the version:

    https://graph.facebook.com/v4.0/me?fields=name,email&access_token=xxxx

    All the existing fields for users are here to find: https://developers.facebook.com/docs/graph-api/reference/user/

    You do not need the User ID, the User Token identifies the User anyway and you can just use "me" instead of the ID. The Graph API is a REST API though, not GraphQL.