0

I am using Facebook Graph API to request some of the users data using javascript fetch method. The problem that the response that returned when I was trying on the Graph API Explorer https://developers.facebook.com/tools/explorer is different than the one that returned to the fetch method.

The request is: https://graph.facebook.com/v2.8/me?fields=birthday%2Cemail%2Cage_range%2Cabout%2Cgender%2Cfirst_name%2Clast_name%2Clocation%7Blocation%7D%2Ccover%2Cpicture.height(800).width(800)%2Chometown%7Blocation%7D&access_token=MY_ACCESS_TOKEN

In the explorer the response returned all the requested data while in the fetch method birthday, location and hometown are missing. so what is the reason behind the difference in these responses?

Here is the Graph API response:

{
   "id": "10152311252041311",
   "birthday": "12/11/1992",
   "age_range": {
      "min": 21
   },
   "gender": "male",
   "first_name": "Karim",
   "last_name": "Elbawab",
   "location": {
      "location": {
         "city": "Cairo",
         "country": "Egypt",
         "latitude": 30.0581,
         "longitude": 31.2289
      },
      "id": "115351105145884"
   },
   "cover": {
      "id": "10153054290206311",
      "offset_y": 36,
      "source": "https://scontent.xx.fbcdn.net/v/t31.0-8/s720x720/11080657_10153054290206311_8236239774331416126_o.jpg?oh=7a5e55ce637ddbcbdacb485c5830bbaf&oe=5998BAC0"
   },
   "picture": {
      "data": {
         "height": 958,
         "is_silhouette": false,
         "url": "https://scontent.xx.fbcdn.net/v/t1.0-1/c1.0.958.958/14492344_10154345907211311_2194946159496032335_n.jpg?oh=27591ffb185acde25518df742f7cbf68&oe=598BA899",
         "width": 958
      }
   },
   "hometown": {
      "location": {
         "city": "Port Said",
         "country": "Egypt",
         "latitude": 31.2667,
         "longitude": 32.3
      },
      "id": "106225446079687"
   }
}

Here is how I am doing the fetch request:

var url = "https://graph.facebook.com/v2.8/me?fields=birthday%2Cemail%2Cage_range%2Cabout%2Cgender%2Cfirst_name%2Clast_name%2Clocation%7Blocation%7D%2Ccover%2Cpicture.height(800).width(800)%2Chometown%7Blocation%7D&";
    url += "access_token=" + accessToken.value;

    fetch(url,{
        method:"GET"
    }).then(function(result){
        var user_info = JSON.parse(result._bodyInit);
        authentication_api.loginWithFacebook(user_info).then(function(res) {
            callback(res);
        });
    }).catch(function(error){
        console.log("Error: " + error);
        callback(error);
    });
}

The Fetch Response:

{"type":"default","status":200,"ok":true,"statusText":"OK","headers":{"map":{"cache-control":["private, no-cache, no-store, must-revalidate"],"x-fb-deb:["kHzlkaPnR7TExQXruPW/ibxz09g8LxiGsofdsFZVCUE4/ij1sebOSAcyn16osY3Q+4czC8MUT1Er5vrr3mueHg=="],"pragma":["no-cache"],"expires":["Sat, 01 Jan 2000 00:00:00 GMT"],"vary":["Accept-Encoding"],"x-fb-tracd":["G9ozccWmdM/"],"x-fb-rev":["2950242"],"x-android-selected-protocol":["http/1.1"],"x-android-response-source":["NETWORK 200"],"connection":["keep-alive"],"x-android-sent-millis":["1491911956237" content-type":["text/javascript; charset=UTF-8"],"date":["Tue, 11 Apr 2017 11:59:17 GMT"],"facebook-api-version":["v2.8"],"etag":["\"515d42cd12052847a3f24b113f810035508e12be\""],"null":["HTTP/1.1 2 OK"],"x-android-received-millis":["1491911956438"],"access-control-allow-origin":["*"]}},"url":"","_bodyInit":"{\"age_range\":{\"min\":21},\"gender\":\"male\",\"first_name\":\"Karim\",\"last_name\" Elbawab\",\"cover\":{\"id\":\"10153054290206311\",\"offset_y\":36,\"source\":\"https:\\/\\/scontent.xx.fbcdn.net\\/v\\/t31.0-8\\/s720x720\\/11080657_10153054290206311_8236239774331416126_o.jpg?oh=755ce637ddbcbdacb485c5830bbaf&oe=5998BAC0\"},\"picture\":{\"data\":{\"height\":958,\"is_silhouette\":false,\"url\":\"https:\\/\\/scontent.xx.fbcdn.net\\/v\\/t1.0-1\\/c1.0.958.958\\/14492344_10154345211311_2194946159496032335_n.jpg?oh=27591ffb185acde25518df742f7cbf68&oe=598BA899\",\"width\":958}},\"id\":\"10154881281451311\"}","_bodyText":"{\"age_range\":{\"min\":21},\"gender\":\"male\",\"first_ame\":\"Karim\",\"last_name\":\"Elbawab\",\"cover\":{\"id\":\"10153054290206311\",\"offset_y\":36,\"source\":\"https:\\/\\/scontent.xx.fbcdn.net\\/v\\/t31.0-8\\/s720x720\\/11080657_1015305429020631236239774331416126_o.jpg?oh=7a5e55ce637ddbcbdacb485c5830bbaf&oe=5998BAC0\"},\"picture\":{\"data\":{\"height\":958,\"is_silhouette\":false,\"url\":\"https:\\/\\/scontent.xx.fbcdn.net\\/v\\/t1.0-1\\/0.958.958\\/14492344_10154345907211311_2194946159496032335_n.jpg?oh=27591ffb185acde25518df742f7cbf68&oe=598BA899\",\"width\":958}},\"id\":\"10154881281451311\"}"}
Karim
  • 198
  • 1
  • 10
  • You should use https://stackoverflow.com/posts/43344809/edit to edit/update your question to include the code you’re using to make the fetch request – sideshowbarker Apr 11 '17 at 11:38
  • I already did, I listed all the requested fields on my request but as shown some of the requested fields were missing – Karim Apr 11 '17 at 12:09
  • 2
    Then your access token likely does not include the permissions necessary to retrieve those fields. – CBroe Apr 11 '17 at 12:21
  • Yes, I discovered that the reason was the access token as I hard coded the one that I got from the Graph API Explorer and it works fine but why the permission differ while I am using the same account in testing – Karim Apr 11 '17 at 12:29

0 Answers0