Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get user location with Facebook Graph API

I am trying this in the graph explorer with my account: https://developers.facebook.com/tools/explorer/?method=GET&path=me

I added to the token all the possibly related permissions. It shows me many info but any location. On my Facebook profile I don't have a hometown but I have the current location, and my friends can see it too. It says I live in *. I couldn't find any privacy settings where I could have set not to show it to any app.

Thanks!

like image 855
Nuthinking Avatar asked Nov 28 '25 22:11

Nuthinking


1 Answers

It was a bit tricky, till I found that hometown and location are stored as single-dimensional array in response data. Try the code below:

FB.api('/me', function(response) {
console.log(response.hometown.name);
console.log(response.location.name);
});

This should work.

like image 116
Aky Joe Avatar answered Nov 30 '25 19:11

Aky Joe