Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Alright, it seems a lot of whining about a simple issue that I still believe my old answer clarifies. Anyway, let me babysit you. :)</p> <p><em>First</em>: 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: <a href="https://developers.facebook.com/bugs/391562790938294?browse=search_50fcac3ce094e7068176315">https://developers.facebook.com/bugs/391562790938294?browse=search_50fcac3ce094e7068176315</a></p> <p><em>Second</em>: If this is by design, you cannot go back to "previous" from the first page (because there <em>is</em> 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.</p> <p><strong>The answer to the question:</strong><br> <em>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?</em></p> <blockquote> <p>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 <code>{"data":[]}</code></p> </blockquote> <p><strong>How to get previous/next page?</strong><br> Here, I am writing a small code that uses jQuery. In case you do not want to read the code, there are two ways: </p> <ol> <li>Use previous/next URL and make HTTP GET request. Which, if not empty, will come with next set of "previous", "next" link.</li> <li>Parse the URL, and get the query-string as JSON ans pass it to <code>FB.api</code>. I used <a href="http://benalman.com/code/projects/jquery-bbq/docs/files/jquery-ba-bbq-js.html#jQuery.deparam">jQuery BBQ pluging</a> for parsing.</li> </ol> <p><strong>Important Note:</strong> 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.</p> <p><strong>Example 1: Code using HTTP GET (preferred):</strong> (I will load 3 posts/page and look three next-pages) </p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="https://raw.github.com/cowboy/jquery-bbq/master/jquery.ba-bbq.min.js"&gt;&lt;/script&gt; &lt;script&gt; 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 &lt; 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); }); }) &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="fb-root"&gt;&lt;/div&gt; &lt;script&gt; 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 }; &lt;/script&gt; &lt;button id="loadPosts"&gt;Load Posts&lt;/button&gt; &lt;p&gt;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&lt;/p&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><em>Response</em>:</p> <pre><code>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&amp;access_token=AAACYjXGS5FQBAIR3brc2LibjBcZCi2kRJUybG8VMaaJSZARQ8SzNE7BE4PBrDIFVZB0AaVEa1dZCpX1fhCvoD2rnq8uc8OGaIFhO9uvVXAZDZD&amp;until=1359184568 367116489976035_536776529676696: Rage. Quit. Life. 899605553_10152450871820554: undefined 367116489976035_417820828298092: undefined https://graph.facebook.com/677811901/home?limit=3&amp;access_token=AAACYjXGS5FQBAIR3brc2LibjBcZCi2kRJUybG8VMaaJSZARQ8SzNE7BE4PBrDIFVZB0AaVEa1dZCpX1fhCvoD2rnq8uc8OGaIFhO9uvVXAZDZD&amp;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 </code></pre> <p><strong>Example 2: Code using FB.api:</strong> (I will load 3 posts/page and look three next-pages)</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="https://raw.github.com/cowboy/jquery-bbq/master/jquery.ba-bbq.min.js"&gt;&lt;/script&gt; &lt;script&gt; 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 &lt; 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); }); }) &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="fb-root"&gt;&lt;/div&gt; &lt;script&gt; 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 }; &lt;/script&gt; &lt;button id="loadPosts"&gt;Load Posts&lt;/button&gt; &lt;p&gt;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&lt;/p&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><em>Response</em>:</p> <pre><code>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&amp;access_token=AAACYjXGS5FQBAIR3brc2LibjBcZCi2kRJUybG8VMaaJSZARQ8SzNE7BE4PBrDIFVZB0AaVEa1dZCpX1fhCvoD2rnq8uc8OGaIFhO9uvVXAZDZD&amp;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 </code></pre> <p><strong>Example 3: Performing: page1 -> page2 -> page1 or page -> next -> previous</strong> The following code will load page1, then go to "next" page (page2), then come back to page1, using "previous"</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="https://raw.github.com/cowboy/jquery-bbq/master/jquery.ba-bbq.min.js"&gt;&lt;/script&gt; &lt;script&gt; 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 &lt; 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); }); }) &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="fb-root"&gt;&lt;/div&gt; &lt;script&gt; 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 }; &lt;/script&gt; &lt;button id="loadPosts"&gt;Load Posts&lt;/button&gt; &lt;p&gt;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&lt;/p&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><em>Response</em>:</p> <pre><code>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&amp;access_token=AAACYjXGS5FQBAKqIMyCVYjH9upK4e2bjUwLoVbbFDL0ffc0SZBTVR9MUFGV4ZCq6HBdFIadFMpLDC3ATMZCJ4GPsXWpG4qTGODavuvzLAZDZD&amp;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&amp;access_token=AAACYjXGS5FQBAKqIMyCVYjH9upK4e2bjUwLoVbbFDL0ffc0SZBTVR9MUFGV4ZCq6HBdFIadFMpLDC3ATMZCJ4GPsXWpG4qTGODavuvzLAZDZD&amp;since=1359185123&amp;__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 </code></pre> <hr> <p><strong>OLD ANSWER</strong> </p> <p>Use <code>limit</code>, <code>offset</code>, <code>since</code> and <code>until</code> parameters to achieve your goal.</p> <p>Refer: <a href="http://developers.facebook.com/docs/reference/api/">http://developers.facebook.com/docs/reference/api/</a></p> <blockquote> <p><strong>Paging</strong></p> <p>When querying connections, there are several useful parameters that enable you to filter and page through connection data:</p> <ul> <li>limit, offset: <a href="https://graph.facebook.com/me/likes?limit=3">https://graph.facebook.com/me/likes?limit=3</a></li> <li>until, since (a unix timestamp or any date accepted by strtotime): <a href="https://graph.facebook.com/search?until=yesterday&amp;q=orange">https://graph.facebook.com/search?until=yesterday&amp;q=orange</a></li> </ul> </blockquote> <p>The following should get all the posts since <code>last week</code> until <code>yesterday</code> from <code>21st - 30th</code> message (basically, third page of 10 message per page pagination).</p> <pre><code> FB.api( '/me/home', { 'since':'last week', 'limit': '10', 'offset': '20', 'until': 'yesterday' }, getPosts ); </code></pre> <hr> <p>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</p> <pre><code>https://graph.facebook.com/me/home?access_token=[AUTH_TOKEN]&amp;since=1296626400&amp;limit=4 </code></pre> <p>It returns the data, plus it also return URL to go to next page</p> <pre><code>{ "data": [ &lt;ARRAY OF POSTS HERE&gt; ], "paging": { "previous": "https://graph.facebook.com/me/home?access_token=[NEW_AUTH_TOKEN]&amp;since=1298026753&amp;limit=4", "next": "https://graph.facebook.com/me/home?access_token=[NEW_AUTH_TOKEN]&amp;limit=4&amp;until=1298023222" } } </code></pre> <p>You can safely use <code>previous</code> and <code>next</code> attributes of the JSON object to jump to next page (or previous page). This seems to be the easiest way to do.</p> <p>By the way, <code>\u00257C</code> needed to be converted to <code>|</code> to get this to work.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload