FB.api分页没有嵌套 [英] FB.api pagination without nesting

查看:79
本文介绍了FB.api分页没有嵌套的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过Facebook的JavaScript API生成一个用户整个朋友列表。我可以使用以下电话获得50位(或更多)的用户朋友。

  FB.api(me /朋友,函数(响应){
//做某事与响应
});

我知道如果用户有更多的朋友,我可以使用以下代码获得50(或更多) :

  FB.api(me / friends,function(response){
if(response.paging。 next $ = $ {
}}
$ code>

然而这不是理想的,因为为了获得一个不确定的长的朋友列表,我只需要嵌套一大堆FB.api功能和希望我有足够的可以任何人建议另一种方式?

解决方案

尝试使用递归:

  FB.api(me / friends,doSomething); 

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

希望这有帮助!


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?

解决方案

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!

这篇关于FB.api分页没有嵌套的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆