FB.api pagination without nesting

…衆ロ難τιáo~ 提交于 2019-12-21 20:46:34

问题


I'm trying to generate a users entire friend list via Facebook's javascript API. I am able to get 50 (or so) of the users friends using the following call.

FB.api("me/friends",function(response){
//Do something with response
});

I know if the user has more friends I can get 50 (or so) more with the following code:

FB.api("me/friends",function(response){
    if (response.paging.next != "undefined"){
        FB.api(response.paging.next,function(response){
        }
     }
});

This however is not ideal because in order to get an indeterminately long friend list I just need to nest a whole bunch of FB.api functions and hope I have enough. Can anyone suggest another way?


回答1:


Try using recursion:

FB.api("me/friends", doSomething);

function doSomething(response){
   if (response.paging.next != "undefined"){
       FB.api(response.paging.next, doSomething);
   }
}

Hope this helps!



来源:https://stackoverflow.com/questions/17416787/fb-api-pagination-without-nesting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!