Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The key constraint in your question is we can't use the 'next' url provided in the response.</p> <p>I'll try to answer your question by first asking a more general question: </p> <blockquote> <p>How can we create a user experience for our Facebook app where every call for more items returns the same amount of items.</p> </blockquote> <p>If the user requests 'more' and gets 10 items, presses 'more' and gets then 4, then 7 etc, she might think our app is buggy.</p> <p>On the Open Graph <a href="https://developers.facebook.com/docs/reference/api/" rel="nofollow">intro page</a>, different parameters for paging are introduced. These are: </p> <blockquote> <p>limit</p> <p>offset</p> <p>until</p> <p>since</p> </blockquote> <p>as mentioned under the 'paging' heading. However if we implement a solution with limit and offset where we increment offset ,e.g.:</p> <pre><code>https://graph.facebook.com/me/home?limit=10&amp;offset=OFFSET </code></pre> <p>where OFFSET will be increased by the limit each request, we find that the number of results returned will sometimes not be equal to the “limit” parameter we specified. This is because parameters are applied on Facebook's side <em>before</em> checking if the queried results are visible to the viewer. We ask for 10, but we might get 8 items in return.</p> <p>This means we can't use a solution where we increment limit and offset if we want our app's 'more' request to always return the same amount of items.</p> <p>A solution proposed in this <a href="https://developers.facebook.com/blog/post/478/" rel="nofollow">blog</a> by Jeff Bowen (who works on the Facebook plaform team) is this logic:</p> <ul> <li>request item with limit = YOUR_LIMIT.</li> <li>retrieve the created_time field of the last item in the response.</li> <li>request next 10 items with since = RETRIEVED_CREATED_TIME and limit=YOUR_LIMIT</li> </ul> <p>Here's a code sample, based on an example in the blog post mentioned above:</p> <pre><code>var graphURL = "https://graph.facebook.com/me/home?" + "callback=processResult&amp;" + "date_format=U&amp;" + "limit=10"; function loadPosts() { var script = document.createElement("script"); script.src = graphURL; document.body.appendChild(script); } function processResult(posts) { if (posts.data.length == 0) { document.getElementById("loadMore").innerHTML = "No more results"; } else { graphURL = graphURL + "&amp;until=" + posts.data[posts.data.length-1].created_time; for (var post in posts.data) { var message = document.createElement("div"); message.innerHTML = posts.data[post].message; document.getElementById("content").appendChild(message); } } } </code></pre> <p>This solution retrieves the next 10 items from the user's newsfeed in chronological order without using the url in the JSON response.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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