Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Graph API: Get user_location

Is there a way to get the location of my facebook friends using the Graph API?

like image 944
Anush Shetty Avatar asked Jan 05 '11 07:01

Anush Shetty


2 Answers

Your friend is considered a user, so you go to the user documentation, get the field name location (to be send in the fields parameter) AND you check if you need a specific permission:

Requires user_location or friend_location permission

HOWEVER there's a typo! to get your friend's location you need the friends_location (with s), reference.

Here's a PHP-SDK example:

$facebook->api('/friend_id', 'get', array("fields"=>"name,location"));

Here I'm retrieving the name and location fields (please note that the id field will be retrieved automatically).

like image 150
ifaour Avatar answered Sep 29 '22 09:09

ifaour


FB.api('/me', function(response) {
    var location = response.location.name;
});
like image 25
Josh R Avatar answered Sep 29 '22 09:09

Josh R