siva siva - 1 year ago 648
Javascript Question

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

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
} 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, ' + + '.' + ' Email: ' + + ' Facebook ID: ' +;
//console.log('Good to see you, ' + + '.');
var userfirstName=response.first_name;
var lastName=response.last_name;
var usersex=response.gender;
var userbithday=response.birthday;
var hometown=;
var location=;




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

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

Answer Source

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=;

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

Graph API Explorer

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download