/* make the API call */
FB.api(
"/me/friends",
function (response) {
if (response && !response.error) {
/* handle the result */
}
}
);
從這段代碼中,我該如何獲取列表的編號? 我對獲取使用我的應用的用戶的朋友總數感興趣。Facebook javascript sdk獲取用戶的朋友總數
/* make the API call */
FB.api(
"/me/friends",
function (response) {
if (response && !response.error) {
/* handle the result */
}
}
);
從這段代碼中,我該如何獲取列表的編號? 我對獲取使用我的應用的用戶的朋友總數感興趣。Facebook javascript sdk獲取用戶的朋友總數
朋友陣列在response.data
。要獲得數組的長度,只需要使用response.data.length
見How to loop through me/friends and assign each user it's picture from {USERID}/picture from FB.api
/* make the API call */
FB.api(
"/me/friends",
function (response) {
if (response && !response.error) {
console.log('Friend count = ', response.data.length);
}
}
);
[1]:
非常感謝! – Min
胡安大多是正確的。
我還建議的唯一的事情是將限制設置爲大於您所期望的或者遍歷分頁的內容:下一個網址。
"paging": {
"next": "https://graph.facebook.com/xxxxxx/friends?limit=5000&offset=5000&__after_id=xxxxxx"
}
默認限制爲5000,雖然這通常不會是普通用戶,名人,企業,問題等可能有更多的朋友,這。
/friends?limit=10000000000
謝謝你,這是一個偉大的想法,我不知道我可以設置! – Min
你試過了什麼? 「響應」是什麼樣的? –
我幾乎不知道JavaScript,所以我不知道...也許迴應應該是這樣的: {「data」:[{「name」:「barack obama」,id:「123456」 },{「name」:「michelle johnson」,id:「63479」}]} – Min
嗯,我知道我必須得到該數組的長度,但我不知道如何... – Min