How to get user location and user hometown in facebook api?

I am already using this script but I didn't get hometown and location when I use API the hometown and location is undefined message appears please give example code and how to get user mobile number in Facebook API:

function login() {
FB.login(function(response) {
    if (response.authResponse) {
        // connected
    testAPI();
    } else {
        // cancelled
    }
}, { scope: 'email,user_birthday,user_location,user_hometown' });
}
function testAPI() {
console.log('Welcome!  Fetching your information.... ');
FB.api('/me', function(response) {
    console.log('Good to see you, ' + response.name + '.' + ' Email: ' +     response.email + ' Facebook ID: ' + response.id);
  //console.log('Good to see you, ' + response.name + '.');
  var userfirstName=response.first_name;
  var lastName=response.last_name;
  var useremail=response.email;
  var usersex=response.gender;
  var userbithday=response.birthday;
  var hometown= response.hometown.name;
  var location= response.location.name;

    alert(hometown);

});

}

 <fb:login-button show-faces="false" width="200" max-rows="1"     scope="email,user_birthday,user_location,user_hometown" onclick="testAPI();" onlogin="Log.info('onlogin callback')">
     Sign Up with Facebook
    </fb:login-button>

but can't get hometown and location, please help give any example.

Answers


You are using wrong permissions, try this:

{ scope: 'email,user_birthday,user_location,user_hometown' }

Another thing, to access the hometown use this:

var hometown= response.hometown.name;

Also, instead of /me; mention explicitly the fields you want using the fields parameter; just like: /me?fields=hometown

Graph API Explorer


Need Your Help

Counting palindromic substrings in O(n)

algorithm string optimization count

Given a string (assume only English characters) S of length n, we can count the number of palindromic substrings with the following algorithm:

String to timestamp in mysql

mysql sql timestamp

Is there any way to convert string to UNIX timestamp in MySQL?