Ben*_*rce 3 pagination facebook facebook-graph-api facebook-javascript-sdk
我正试图通过Facebook的JavaScript API生成用户整个朋友列表.我可以使用以下呼叫获得50个(左右)用户朋友.
FB.api("me/friends",function(response){
//Do something with response
});
Run Code Online (Sandbox Code Playgroud)
我知道如果用户有更多朋友,我可以使用以下代码获得50(或更多)
FB.api("me/friends",function(response){
if (response.paging.next != "undefined"){
FB.api(response.paging.next,function(response){
}
}
});
Run Code Online (Sandbox Code Playgroud)
然而这并不理想,因为为了得到一个不确定的长朋友列表,我只需要嵌套一大堆FB.api函数,并希望我有足够的.谁能提出另一种建议?
小智 12
尝试使用递归:
FB.api("me/friends", doSomething);
function doSomething(response){
if (response.paging.next != "undefined"){
FB.api(response.paging.next, doSomething);
}
}
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助!
| 归档时间: |
|
| 查看次数: |
2955 次 |
| 最近记录: |