Consuming facebook graph api

I’m using the expo api to implement Facebook login in my app. The login works just fine, but when I try to access the graph api, I’m only getting the name and the id - no matter what I request.

My code is as follows -

login = async() => {
  const APP_ID = '1121020794696681';
  const options = {
    permissions: ['public_profile', 'email', 'user_friends']
  }
  const {type, token} = await Expo.Facebook.logInWithReadPermissionsAsync(APP_ID, options);
  if(type=='success') {
    const response = await fetch(`https://graph.facebook.com/v2.9/me?access_token=${token}`);
    console.log(await response.json());
    
  }
}

The output that I get in the console is -
Object {
“id”: “10211949495125019”,
“name”: “Sambhav Anand”,
}

Since I’m requesting a user object and then printing that out, why am I not getting access to all the other data in the public_profile permission

1 Like

This sounds like more of an issue with the Facebook API. You could try making the request with an API testing tool to double check that you’re sending the correct request.

I used the same code, which is recommended by the expo docs and the response is identical to sambhavanand’s. I’m trying to get access to the email address. Can anyone help with this?

1 Like

I’m having this same issue. According to the Facebook docs, there should be additional data (picture, link, etc.) that comes along with the returned data. Why would this not be the case for the Expo version?

Also, I tried adding user_friends and email permissions as well, and still got only name and id back.

1 Like

I put together a Snack that works for me! It looks like you are missing some fields at the end of your Graph call… :sweat_smile::blue_heart:
https://snack.expo.io/@bacon/facebook-login-+-graph-api

Here is what my profile looks like:

Yes, thank you @bacon! The issue was simple: I was missing the fields param at the end of the Graph API call, like so:

https://graph.facebook.com/me?access_token=${token}&fields=id,name,email,picture

I really appreciate the help :slight_smile:

3 Likes