How does paging in facebook javascript API work?

前端 未结 5 1810
粉色の甜心
粉色の甜心 2020-11-29 19:45

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 iteratin

5条回答
  •  遥遥无期
    2020-11-29 20:39

    I noticed the question is very old. My answer is true for the these days FB jsSDK (2017) :)

    Actually it's simpler than what predecessors described and somewhat intuitive. FB jsSDK it is an API itself and it is expected to be able to navigate through pages of the response by itself and using same means, no?

    function getPosts(){
        FB.api('/me/posts', 'GET', {limit:250}, cbGetPosts);
    }
    
    function cbGetPosts(response){
        // do your stuff with response.data
        if(response && response.paging){
         FB.api(response.paging.next, cbGetPosts); // yep, is this simple
        }
    }
    

    Obviously this will request for next pages as long as there is a next key defined but s proving the concept.

提交回复
热议问题