Reputation: 225
Is there a way to get the location of my facebook friends using the Graph API?
Upvotes: 6
Views: 30954
Reputation: 31
FB.api('/me', function(response) {
document.getElementById("UserLocation").innerHTML = response.location.name;
});
In your HTML code call UserLocation
Id in any HTML tag. ex.
<div id="UserLocation"></div>
Upvotes: 0
Reputation: 197
fql?q=SELECT locale,current_location from user where uid in(select uid2 from friend where uid1=me())
Requires user_location or friend_location permission
Upvotes: 1
Reputation: 393
https://graph.facebook.com/me/friends?access_token="get this from fb tool"&fields=location
Upvotes: 1
Reputation: 7935
The fastest way to get all the information you want from friends of a user you can use the FQL method:
$this->api->api(array('method'=>'fql.query','query'=>"SELECT uid,name,first_name,middle_name,last_name,pic_square,hometown_location,current_location,profile_url,email,website FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())"));
For a list of all the tables with their corresponding column names I refer to: Facebook FQL Reference
Upvotes: 2
Reputation: 287
The FaceBook Documentation has the information you're looking for, including sample code and instructions. It's available at:
http://developers.facebook.com/docs/guides/canvas
You may also find the Graph API useful: http://developers.facebook.com/docs/api
Upvotes: 1
Reputation: 38135
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
orfriend_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).
Upvotes: 8
Reputation: 1295
FB.api('/me', function(response) {
var location = response.location.name;
});
Upvotes: 2