Facebook JavaScript API中的分页如何工作? [英] How does paging in facebook javascript API work?

查看:96
本文介绍了Facebook JavaScript API中的分页如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过javascript sdk恢复我的Facebook新闻Feed中的上周帖子。
我可以获得第一页,但是我不知道如何继续迭代其他页面。我试过以下代码:

  $('#loadPosts')bind('click',function ){
FB.api('/ me / home',{since:'last week'},getPosts);
});

getPosts = function(response){
for(element in response.data){
post = response.data [element]
console.log(post) ;
}

previousPage = response.paging.previous;
console.log(previousPage);

//可以调用FB.api(previousPage,getPosts); ??

}

但是我得到一个URL作为上一页,不知道如何从该网址进行javascript FB.api调用。任何想法?

解决方案

好的,对于一个简单的问题,我仍然相信我的旧答案澄清了很多。无论如何,让我保姆你。 :)



首先:我发现你不能真正从第一页到上一页。理想的,我应该所以,这里是我提交的一个错误,你可能想要遵循: https://developers.facebook.com/ bug / 391562790938294?browse = search_50fcac3ce094e7068176315



第二个:如果这是按设计,你不能回到第一页(因为 没有以前的),但你可以肯定地进入下一步。但是,由于API作为游标,您已经向前移动,现在您的上一页将会起作用。



问题的答案: / strong>

我得到一个URL作为上一页,我不知道如何从该URL进行一个javascript FB.api调用。任何想法?


是的,你可以使FB.api调用。但是我建议您改为使用HTTP GET调用,因为它更容易。另外,请注意,以前可能会返回和空数组,如 {data:[]}


如何获取上一页/下一页?

这里,我正在编写一个使用jQuery的小代码。如果您不想阅读代码,有两种方法:


  1. 使用上一个/下一个URL并进行HTTP GET请求。如果不是空的,将会带有下一组上一个,下一个链接。

  2. 解析URL,并将查询字符串作为JSON传递给 FB.api 。我使用 jQuery BBQ pluging

重要提示:在示例中,我使用下一个网址,因为第一个请求,如果我使用上一个它给空的JSON,而不是给过去的帖子。但是,一旦我提前了几页,我可以使用以前的URL。像Google结果一样,您无法前往第1页,但可以从任何页面> 1(参见下面的示例3)。



示例1:使用HTTP GET(首选)的代码:(我将加载3个帖子/页面并查看三个下一个pages)

 < html> 
< head>
< script type =text / javascriptsrc =http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js>< / script>
< script type =text / javascriptsrc =http://connect.facebook.net/en_US/all.js>< / script>
< script type =text / javascriptsrc =https://raw.github.com/cowboy/jquery-bbq/master/jquery.ba-bbq.min.js>< /脚本>
< script>

var i = 0;
var getPosts = function(response){
for(element in response.data){
post = response.data [element]
console.log(post.id + :+ post.message);
}



//我可以调用FB.api(nextPage,getPosts); ??
if(i< 2){
nextPage = response.paging.next;
console.log(nextPage);
i ++;
//方法1:我用它
$ .get(nextPage,getPosts,json); //可选:$ .getJSON可以使用
}

}

$(document).ready(function(){

$('#loadPosts')。bind('click',function(){
FB.api('/ me / home',{since:'yesterday','limit':'3'} ,getPosts);
});
})
< / script>
< / head>
< body>
< div id =fb-root>< / div>
< script>
window.fbAsyncInit = function(){
//初始化FB JS SDK
FB.init({
appId:'XXXXXXXXXXXX',//填写您的应用程序ID!
status:true,//在初始化时检查登录状态
cookie:true,//设置会话cookie以允许您的服务器访问会话?
});

//附加的初始化代码如添加事件侦听器在这里

};
< / script>
< button id =loadPosts>加载帖子< / button>
< p>请打开开发者控制台,看看发生了什么。在Firefox中,您可以使用ctrl + shift + k,并在Chrome / Chromium中使用ctrl + shift + i< / p>
< / body>
< / html>

回应

  100004192352945_156620584487686:未定义
137723270230_10152423499430231:在这一天,请为那些同情公民的思想留下深刻的印象,我只想一想,不做任何其他事情。
642965867_10151211036740868:感谢大家的意愿!愿望使我的一天!

https://graph.facebook.com/677811901/home?limit=3&access_token=AAACYjXGS5FQBAIR3brc2LibjBcZCi2kRJUybG8VMaaJSZARQ8SzNE7BE4PBrDIFVZB0AaVEa1dZCpX1fhCvoD2rnq8uc8OGaIFhO9uvVXAZDZD&until=1359184568
367116489976035_536776529676696:愤怒。放弃。生活。
899605553_10152450871820554:未定义
367116489976035_417820828298092:未定义

https://graph.facebook.com/677811901/home?limit=3&access_token=AAACYjXGS5FQBAIR3brc2LibjBcZCi2kRJUybG8VMaaJSZARQ8SzNE7BE4PBrDIFVZB0AaVEa1dZCpX1fhCvoD2rnq8uc8OGaIFhO9uvVXAZDZD&until=1359179890
137723270230_10152423148745231:Pratibha Patil曾经爱过共和国游行,特别是访问的首席访客邀请他访问他/她自己的国家的部分。
137723270230_10152423131700231:共和日游行中的翠鸟桌面非常简单。 Vijay Mallya骑自行车。
367116489976035_484460034950769:undefined

示例2:使用FB.api的代码: strong>(我将加载3个帖子/页面并查看三个下一页)

 < html> 
< head>
< script type =text / javascriptsrc =http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js>< / script>
< script type =text / javascriptsrc =http://connect.facebook.net/en_US/all.js>< / script>
< script type =text / javascriptsrc =https://raw.github.com/cowboy/jquery-bbq/master/jquery.ba-bbq.min.js>< /脚本>
< script>

var i = 0;
var getPosts = function(response){
for(element in response.data){
post = response.data [element]
console.log(post.id + :+ post.message);
}



//我可以调用FB.api(nextPage,getPosts); ??
if(i< 2){
nextPage = response.paging.next;
console.log(nextPage);
i ++;

//方法2:如果你必须调用FB.api
var params = jQuery.deparam.querystring(nextPage);
console.log(JSON.stringify(params,null,2));
FB.api('/ me / home',params,getPosts)
}

}

$(document).ready(function ){

$('#loadPosts')。bind('click',function(){
FB.api('/ me / home',{since:'yesterday' 'limit':'3'},getPosts);
});
})
< / script>
< / head>
< body>
< div id =fb-root>< / div>
< script>
window.fbAsyncInit = function(){
//初始化FB JS SDK
FB.init({
appId:'XXXXXXXXXXXX',//填写您的应用程序ID!
status:true,//在初始化时检查登录状态
cookie:true,//设置会话cookie以允许您的服务器访问会话?
});

//附加的初始化代码如添加事件侦听器在这里

};
< / script>
< button id =loadPosts>加载帖子< / button>
< p>请打开开发者控制台,看看发生了什么。在Firefox中,您可以使用ctrl + shift + k,并在Chrome / Chromium中使用ctrl + shift + i< / p>
< / body>
< / html>

回应

  367116489976035_536776529676696:愤怒。放弃。生活。 
899605553_10152450871820554:未定义
367116489976035_417820828298092:未定义
{
极限: 3,
的access_token: AAACYjXGS5FQBAIR3brc2LibjBcZCi2kRJUybG8VMaaJSZARQ8SzNE7BE4PBrDIFVZB0AaVEa1dZCpX1fhCvoD2rnq8uc8OGaIFhO9uvVXAZDZD,
直到 :1359179890
}

137723270230_10152423148745231:Pratibha Patil曾经喜欢共和国游行,特别是访问的首席客人邀请他访问他/她自己的国家的部分。
137723270230_10152423131700231:共和日游行中的翠鸟桌面非常简单。 Vijay Mallya骑自行车。
367116489976035_484460034950769:未定义

https://graph.facebook.com/677811901/home?limit=3&access_token=AAACYjXGS5FQBAIR3brc2LibjBcZCi2kRJUybG8VMaaJSZARQ8SzNE7BE4PBrDIFVZB0AaVEa1dZCpX1fhCvoD2rnq8uc8OGaIFhO9uvVXAZDZD&until=1359178140
{
限: 3,
的access_token: AAACYjXGS5FQBAIR3brc2LibjBcZCi2kRJUybG8VMaaJSZARQ8SzNE7BE4PBrDIFVZB0AaVEa1dZCpX1fhCvoD2rnq8uc8OGaIFhO9uvVXAZDZD,
直到: 1359178140
}
655515199_403590309726450:良好的分辨率承担共和国日
505588854_496901583686790:爱慢动作的秘密世界揭示。
693811975_10151217837201976:未定义

示例3:执行:page1 - > page2 - >以下代码将加载第1页,然后转到下一页(第2页),然后返回到第1页,使用上一页

 < html> 
< head>
< script type =text / javascriptsrc =http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js>< / script>
< script type =text / javascriptsrc =http://connect.facebook.net/en_US/all.js>< / script>
< script type =text / javascriptsrc =https://raw.github.com/cowboy/jquery-bbq/master/jquery.ba-bbq.min.js>< /脚本>
< script>

var i = 0;
var getPosts = function(response){
for(element in response.data){
post = response.data [element]
console.log(post.id + :+ post.message);
}



//我可以调用FB.api(nextPage,getPosts); ??
if(i< 2){
nextPage = response.paging.next;
if(i == 1)
nextPage = response.paging.previous;

console.log(nextPage);
i ++;
$ .get(nextPage,getPosts,json); //可选:$ .getJSON可以使用
}

}

$(document).ready(function(){

$('#loadPosts')。bind('click',function(){
FB.api('/ me / home',{since:'yesterday','limit':'3'} ,getPosts);
});
})
< / script>
< / head>
< body>
< div id =fb-root>< / div>
< script>
window.fbAsyncInit = function(){
//初始化FB JS SDK
FB.init({
appId:'XXXXXXXXXXXX',//填写您的应用程序ID!
status:true,//在初始化时检查登录状态
cookie:true,//设置会话cookie以允许您的服务器访问会话?
});

//附加的初始化代码如添加事件侦听器在这里

};
< / script>
< button id =loadPosts>加载帖子< / button>
< p>请打开开发者控制台,看看发生了什么。在Firefox中,您可以使用ctrl + shift + k,并在Chrome / Chromium中使用ctrl + shift + i< / p>
< / body>
< / html>

回应

  PAGE1:
367116489976035_536806916340324:太阳系有多大?
完整信息图:http://bit.ly/WmzfVn
137723270230_10152423534790231:社会学家Ashis Nandy称,大部分腐败者来自OBC / SC / ST。
此后,腐败人士强烈谴责南迪企图将他们分为种姓线。他们将在战利品中永远统一起来。
100004192352945_156620584487686:未定义

PAGE2:
https://graph.facebook.com/677811901/home?limit=3&access_token=AAACYjXGS5FQBAKqIMyCVYjH9upK4e2bjUwLoVbbFDL0ffc0SZBTVR9MUFGV4ZCq6HBdFIadFMpLDC3ATMZCJ4GPsXWpG4qTGODavuvzLAZDZD&until=1359185659

137723270230_10152423499430231:在这一天,请为那些同情公民的思想留下深刻的印象,对此,我只是想一想,什么都不做。
642965867_10151211036740868:感谢大家的意愿!愿望使我的一天!
367116489976035_536776529676696:愤怒。放弃。生活。

PAGE1:
https://graph.facebook.com/677811901/home?limit=3&access_token=AAACYjXGS5FQBAKqIMyCVYjH9upK4e2bjUwLoVbbFDL0ffc0SZBTVR9MUFGV4ZCq6HBdFIadFMpLDC3ATMZCJ4GPsXWpG4qTGODavuvzLAZDZD&since=1359185123&__previous=1

367116489976035_536806916340324:太阳系有多大?
完整信息图:http://bit.ly/WmzfVn
137723270230_10152423534790231:社会学家Ashis Nandy称,大部分腐败者来自OBC / SC / ST。
此后,腐败人士强烈谴责南迪企图将他们分为种姓线。他们将在战利品中永远统一起来。
100004192352945_156620584487686:未定义






旧答案



使用限制 offset 直到参数来实现您的目标。



参考: http://developers.facebook.com/docs/reference/api/


分页



当查询连接时,有几个有用的参数可让您过滤和浏览连接数据:




以下内容应该从上周以上的所有帖子直到昨天 21st - 30th 消息(基本上,每页分页的10条消息的第三页)。

  FB.api(
'/ me / home',
{
'since':'上周',
'limit':'10',
'offset':'20',
'until':'yesterday'
},
getPosts
) ;






我刚刚测试过,它的工作原理。我使用了limit = 4,这是页面大小的事情。所以,当我从2011年2月02日起获取数据(Unix时间戳:1296626400),直到今天使用这个

  https:// graph.facebook.com/me/home?access = _ = 

它返回数据,加上它还返回URL进入下一页

  {
data :[
<这里的阵列>
],
分页:{
previous:https://graph.facebook.com/me/home?access_token=[NEW_AUTH_TOKEN]&since=1298026753&limit = 4,
next:https://graph.facebook.com/me/home?access_token=[NEW_AUTH_TOKEN]&limit=4&until=1298023222
}

您可以安全地使用以前的 next JSON对象的属性跳转到下一页(或上一页)。这似乎是最简单的方法。



顺便说一下, \\\%7C 需要转换为 | 以使其正常工作。


I'm trying to recover the last week posts in my facebook news feed with the javascript sdk. I'm able to get the first page but then, I don't know how to continue iterating through the other pages. I've tried it with the following code:

 $('#loadPosts').bind('click', function() {     
            FB.api('/me/home',{since:'last week'}, getPosts);   
          });

 getPosts = function(response){
        for (element in response.data){
            post = response.data[element]
            console.log(post);          
          }

          previousPage = response.paging.previous;        
          console.log(previousPage);

          // can i call FB.api(previousPage, getPosts); ??      

      }

But I'm getting a URL as previous page and I don't know how to make a javascript FB.api call from that URL. Any ideas?

解决方案

Alright, it seems a lot of whining about a simple issue that I still believe my old answer clarifies. Anyway, let me babysit you. :)

First: I find out that you cannot really go to the "previous" page from the first page. Ideally, I should. So, here is a bug that I have filed you may want to follow: https://developers.facebook.com/bugs/391562790938294?browse=search_50fcac3ce094e7068176315

Second: If this is by design, you cannot go back to "previous" from the first page (because there is no previous), but you can surely go to "Next". However, since the API behaves as a cursor, and you have moved forward, now your "previous" page would work.

The answer to the question:
I'm getting a URL as previous page and I don't know how to make a javascript FB.api call from that URL. Any ideas?

yes, you can make FB.api call. But I suggest you to make a HTTP GET call instead, because it's easier. Also, note that previous may return and empty array like {"data":[]}

How to get previous/next page?
Here, I am writing a small code that uses jQuery. In case you do not want to read the code, there are two ways:

  1. Use previous/next URL and make HTTP GET request. Which, if not empty, will come with next set of "previous", "next" link.
  2. Parse the URL, and get the query-string as JSON ans pass it to FB.api. I used jQuery BBQ pluging for parsing.

Important Note: In the example, I am using "next" URL because on the first request if I use "previous" it gives empty JSON instead of giving posts from the past. However, I can use use "previous" URL once I have moved ahead a few pages. Like Google results, you can not go previous on page 1, but you can from any page > 1 (see Example 3 below). This is called pagination.

Example 1: Code using HTTP GET (preferred): (I will load 3 posts/page and look three next-pages)

<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>
<script type="text/javascript" src="https://raw.github.com/cowboy/jquery-bbq/master/jquery.ba-bbq.min.js"></script>
<script>

var i =0;
var getPosts = function (response){
          for (element in response.data){
            post = response.data[element]
            console.log(post.id + ": " +post.message);          
          }



          // can i call FB.api(nextPage, getPosts); ??
          if(i < 2){
              nextPage = response.paging.next;        
              console.log(nextPage);
              i++;
              //Method 1: I use it.
              $.get(nextPage, getPosts, "json"); //optional: $.getJSON can be use instead
          }

      }

$(document).ready(function(){

$('#loadPosts').bind('click', function() {
            FB.api('/me/home',{since:'yesterday','limit': '3'}, getPosts);   
          });
})
</script>
</head>
<body>
<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    // init the FB JS SDK
    FB.init({
      appId      : 'XXXXXXXXXXXX', // FILL YOUR APP ID HERE!
      status     : true, // check the login status upon init?
      cookie     : true, // set sessions cookies to allow your server to access the session?
    });

    // Additional initialization code such as adding Event Listeners goes here

  };
</script>
<button id="loadPosts">Load Posts</button>
<p>Please open developer console to see what's happening. In Firefox, you can use ctrl+shift+k, and in Chrome/Chromium use ctrl+shift+i</p>
</body>
</html>

Response:

100004192352945_156620584487686: undefined
137723270230_10152423499430231: On this day, please spare a thought for those fellow citizens, for whom I just spare a thought and do nothing else.
642965867_10151211036740868: Thanks everyone for their wishes! The wishes made my day!

https://graph.facebook.com/677811901/home?limit=3&access_token=AAACYjXGS5FQBAIR3brc2LibjBcZCi2kRJUybG8VMaaJSZARQ8SzNE7BE4PBrDIFVZB0AaVEa1dZCpX1fhCvoD2rnq8uc8OGaIFhO9uvVXAZDZD&until=1359184568
367116489976035_536776529676696: Rage. Quit. Life.
899605553_10152450871820554: undefined
367116489976035_417820828298092: undefined

https://graph.facebook.com/677811901/home?limit=3&access_token=AAACYjXGS5FQBAIR3brc2LibjBcZCi2kRJUybG8VMaaJSZARQ8SzNE7BE4PBrDIFVZB0AaVEa1dZCpX1fhCvoD2rnq8uc8OGaIFhO9uvVXAZDZD&until=1359179890
137723270230_10152423148745231: Pratibha Patil used to love the Republic Day Parade, especially the part where the visiting Chief Guest extended her an invitation to visit his/her own country.
137723270230_10152423131700231: The Kingfisher tableau at Republic Day Parade was so simple. Vijay Mallya riding a bicycle.
367116489976035_484460034950769: undefined

Example 2: Code using FB.api: (I will load 3 posts/page and look three next-pages)

<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>
<script type="text/javascript" src="https://raw.github.com/cowboy/jquery-bbq/master/jquery.ba-bbq.min.js"></script>
<script>

var i =0;
var getPosts = function (response){
          for (element in response.data){
            post = response.data[element]
            console.log(post.id + ": " +post.message);          
          }



          // can i call FB.api(nextPage, getPosts); ??
          if(i < 2){
              nextPage = response.paging.next;        
              console.log(nextPage);
              i++;

              //Method 2: If you have to call FB.api
              var params = jQuery.deparam.querystring(nextPage);
              console.log(JSON.stringify(params, null, 2));
              FB.api('/me/home', params, getPosts)
          }

      }

$(document).ready(function(){

$('#loadPosts').bind('click', function() {
            FB.api('/me/home',{since:'yesterday','limit': '3'}, getPosts);   
          });
})
</script>
</head>
<body>
<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    // init the FB JS SDK
    FB.init({
      appId      : 'XXXXXXXXXXXX', // FILL YOUR APP ID HERE!
      status     : true, // check the login status upon init?
      cookie     : true, // set sessions cookies to allow your server to access the session?
    });

    // Additional initialization code such as adding Event Listeners goes here

  };
</script>
<button id="loadPosts">Load Posts</button>
<p>Please open developer console to see what's happening. In Firefox, you can use ctrl+shift+k, and in Chrome/Chromium use ctrl+shift+i</p>
</body>
</html>

Response:

367116489976035_536776529676696: Rage. Quit. Life.
899605553_10152450871820554: undefined
367116489976035_417820828298092: undefined
{
  "limit": "3",
  "access_token": "AAACYjXGS5FQBAIR3brc2LibjBcZCi2kRJUybG8VMaaJSZARQ8SzNE7BE4PBrDIFVZB0AaVEa1dZCpX1fhCvoD2rnq8uc8OGaIFhO9uvVXAZDZD",
  "until": "1359179890"
}

137723270230_10152423148745231: Pratibha Patil used to love the Republic Day Parade, especially the part where the visiting Chief Guest extended her an invitation to visit his/her own country.
137723270230_10152423131700231: The Kingfisher tableau at Republic Day Parade was so simple. Vijay Mallya riding a bicycle.
367116489976035_484460034950769: undefined

https://graph.facebook.com/677811901/home?limit=3&access_token=AAACYjXGS5FQBAIR3brc2LibjBcZCi2kRJUybG8VMaaJSZARQ8SzNE7BE4PBrDIFVZB0AaVEa1dZCpX1fhCvoD2rnq8uc8OGaIFhO9uvVXAZDZD&until=1359178140
{
  "limit": "3",
  "access_token": "AAACYjXGS5FQBAIR3brc2LibjBcZCi2kRJUybG8VMaaJSZARQ8SzNE7BE4PBrDIFVZB0AaVEa1dZCpX1fhCvoD2rnq8uc8OGaIFhO9uvVXAZDZD",
  "until": "1359178140"
}
655515199_403590309726450: a good resolution to take on Republic Day
505588854_496901583686790: Love the secret world that slow motion reveals.
693811975_10151217837201976: undefined

Example 3: Performing: page1 -> page2 -> page1 or page -> next -> previous The following code will load page1, then go to "next" page (page2), then come back to page1, using "previous"

<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>
<script type="text/javascript" src="https://raw.github.com/cowboy/jquery-bbq/master/jquery.ba-bbq.min.js"></script>
<script>

var i =0;
var getPosts = function (response){
          for (element in response.data){
            post = response.data[element]
            console.log(post.id + ": " +post.message);          
          }



          // can i call FB.api(nextPage, getPosts); ??
          if(i < 2){
              nextPage = response.paging.next;        
              if(i==1)
                nextPage = response.paging.previous;

              console.log(nextPage);
              i++;
              $.get(nextPage, getPosts, "json"); //optional: $.getJSON can be use instead
          }

      }

$(document).ready(function(){

$('#loadPosts').bind('click', function() {
            FB.api('/me/home',{since:'yesterday','limit': '3'}, getPosts);   
          });
})
</script>
</head>
<body>
<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    // init the FB JS SDK
    FB.init({
      appId      : 'XXXXXXXXXXXX', // FILL YOUR APP ID HERE!
      status     : true, // check the login status upon init?
      cookie     : true, // set sessions cookies to allow your server to access the session?
    });

    // Additional initialization code such as adding Event Listeners goes here

  };
</script>
<button id="loadPosts">Load Posts</button>
<p>Please open developer console to see what's happening. In Firefox, you can use ctrl+shift+k, and in Chrome/Chromium use ctrl+shift+i</p>
</body>
</html>

Response:

PAGE1:
367116489976035_536806916340324: How big is the Solar System?
Full infographic here: http://bit.ly/WmzfVn
137723270230_10152423534790231: "Sociologist" Ashis Nandy has claimed that most of the corrupt came from OBC/SC/ST castes.
Following this, Corrupt people have strongly condemned Nandy's attempts to divide them on caste lines. They'll be united in loot, forever.
100004192352945_156620584487686: undefined

PAGE2:
https://graph.facebook.com/677811901/home?limit=3&access_token=AAACYjXGS5FQBAKqIMyCVYjH9upK4e2bjUwLoVbbFDL0ffc0SZBTVR9MUFGV4ZCq6HBdFIadFMpLDC3ATMZCJ4GPsXWpG4qTGODavuvzLAZDZD&until=1359185659

137723270230_10152423499430231: On this day, please spare a thought for those fellow citizens, for whom I just spare a thought and do nothing else.
642965867_10151211036740868: Thanks everyone for their wishes! The wishes made my day!
367116489976035_536776529676696: Rage. Quit. Life.

PAGE1:
https://graph.facebook.com/677811901/home?limit=3&access_token=AAACYjXGS5FQBAKqIMyCVYjH9upK4e2bjUwLoVbbFDL0ffc0SZBTVR9MUFGV4ZCq6HBdFIadFMpLDC3ATMZCJ4GPsXWpG4qTGODavuvzLAZDZD&since=1359185123&__previous=1

367116489976035_536806916340324: How big is the Solar System?
Full infographic here: http://bit.ly/WmzfVn
137723270230_10152423534790231: "Sociologist" Ashis Nandy has claimed that most of the corrupt came from OBC/SC/ST castes.
Following this, Corrupt people have strongly condemned Nandy's attempts to divide them on caste lines. They'll be united in loot, forever.
100004192352945_156620584487686: undefined


OLD ANSWER

Use limit, offset, since and until parameters to achieve your goal.

Refer: http://developers.facebook.com/docs/reference/api/

Paging

When querying connections, there are several useful parameters that enable you to filter and page through connection data:

The following should get all the posts since last week until yesterday from 21st - 30th message (basically, third page of 10 message per page pagination).

 FB.api(
  '/me/home',
  {
    'since':'last week',
    'limit': '10',
    'offset': '20',
    'until': 'yesterday'
  }, 
  getPosts
); 


I've just tested, it works. I have used limit=4, which is page-size kind of thing. So, when I fetch data since Feb 02, 2011 (Unix Time Stamp: 1296626400) till today using this

https://graph.facebook.com/me/home?access_token=[AUTH_TOKEN]&since=1296626400&limit=4

It returns the data, plus it also return URL to go to next page

{
   "data": [
      <ARRAY OF POSTS HERE>
   ],
   "paging": {
      "previous": "https://graph.facebook.com/me/home?access_token=[NEW_AUTH_TOKEN]&since=1298026753&limit=4",
      "next": "https://graph.facebook.com/me/home?access_token=[NEW_AUTH_TOKEN]&limit=4&until=1298023222"
   }
}

You can safely use previous and next attributes of the JSON object to jump to next page (or previous page). This seems to be the easiest way to do.

By the way, \u00257C needed to be converted to | to get this to work.

这篇关于Facebook JavaScript API中的分页如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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