0

I'm using Facebook Javascript SDK v2.5 and the facebook graph API to access the user location data (more specifically street, zip and city) with following code:

window.fbAsyncInit = function() {
  FB.init({
      appId      : 'my_app_ID',
      xfbml      : true,
      version    : 'v2.5'
  });
};

(function(d, s, id){
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) {return;}
     js = d.createElement(s); js.id = id;
     js.src = "//connect.facebook.net/en_US/sdk.js";
     fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

function logIntoFB(){
    FB.login(function(){
            testAPI();
    }, {scope: 'public_profile,email,user_location'});

    function testAPI() { 
        FB.api('/me?fields=name,first_name,last_name,location',function(response) { 
           console.log(response); 
        });
    }
}

When the user logs in and the response is logged to the console, it looks as follows:

Object {name: "MyFirstName MyLastName", first_name: "MyFirstName", last_name: "MyLastName"
, id: "01010101010101"}

There is no location object present, so I cannot fetch the location.city, etc. The privacy settings of the specific facebook account were not altered and an address was provided, so the information should be retrievable. I already checked the Facebook SDK docs and various questions on StackOverflow, but nothing seems to work. Some of them being: "Facebook user location using fb.api" and "Retrieve zip code of a facebook user by facebook graph API"

Any help would be greatly appreciated.

Community
  • 1
  • 1
Jenever
  • 500
  • 5
  • 17

1 Answers1

0

First make sure that you are asking for this permission during log in (you can look at the list of permissions in the login dialog of your app).

Next, you can grab the access token and use the access token debugger to see if it contains the user_location permission. If this permission is missing, then it can mean either:

  1. The user either declined this permission during login.
  2. Your app has not been approved to use this permission and you are testing this with a user who has no role in your app. Unapproved permissions only work with admins/developers of the app.
bangdel
  • 2,523
  • 5
  • 28
  • 42