开发者

Facebook Graph API: Get user_location

Is there a way to get the lo开发者_如何学JAVAcation of my facebook friends using the Graph API?


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).


FB.api('/me', function(response) {
    var location = response.location.name;
});


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


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


https://graph.facebook.com/me/friends?access_token="get this from fb tool"&fields=location


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


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>        
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜