使用Graph API获取好友数据 [英] Fetch friends data with Graph API
问题描述
-
我需要获取用户的下一个字段的数据:id,name,
gender,birthday,city,country,profileUrl,pic,pic_small,
pic_big ,is_app_user。
I need fetch user's friends data with next fields: id, name, gender, birthday, city, country, profileUrl, pic, pic_small, pic_big, is_app_user.
在使用FB.Data.query之前,现在已经弃用了。
Before I used FB.Data.query, but now it's deprecated.
FB.Data.query('select uid, first_name, last_name, name, pic,
pic_small, pic_big, birthday_date, sex, current_location,
profile_url, is_app_user from user where uid in (select uid2 from
friend where uid1 = {0}', uid).
如何获取朋友,谁正在使用应用程序?
How to fetch friends, who are using app?
我可以获得所需的所有字段,但是照片的例子我需要做其他的请求,我可以在单一请求中获取所有需要的字段吗?
I can get all fields what i need, but for example for pictures i need to do additional requests. Can i get all needed fields in single request?
推荐答案
你仍然可以使用相同的 FQL 查询与 Graph API 和 JavaScript SDK
You can still use same FQL query with Graph API and JavaScript SDK
var query = 'SELECT uid, first_name, last_name, name, pic, pic_small, pic_big, birthday_date, sex, current_location, profile_url, is_app_user FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = ' + uid;
FB.api('/fql',{q:query}, function(response){
console.log(response.data);
});
You for sure can also get almost same data with Graph API not using FQL at all:
FB.api('/'+uid+'/friends', {
fields: 'id,first_name,last_name,name,birthday,gender,location,link,installed'
}, function(response){
console.log(response.data);
});
您有不同的名称和其他格式(ex location
),并忽略结果中的图片详细信息,但这很简单, 用户
图片可在网址以 http://graph.facebook.com/USER_ID/picture
You have a bit different names and other format (ex location
) for those details and miss the picture details in results but this is simple, user
picture is available on URL in form http://graph.facebook.com/USER_ID/picture
use?type = square |小|正常|大要请求不同的照片
use ?type=square | small | normal | large to request a different photo
这篇关于使用Graph API获取好友数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!