title: How can I do pagination when downloading facebook posts via javascript and FB.api?
body: <p>I am trying to download facebook wall posts via the javascript SDK. I managed to do a call for the first 25 posts, but I get into trouble when I am trying to get paging.next and feed that into a new call using a loop, and then iterate over that until no more pages is available.</p>
  
  <p>The code produces the same page 10 times which I do not understand. It should give the next page and the next page and the next page..?</p>
  
  <pre><code>FB.login(function(response){
  
          // FIRST CALL THAT CALLS FOR PAGENAME/FEED
          FB.api(request, function (response) {
  
              // PRINTS TO LOG AND DECLARES X AS THE NEXT PAGE
              console.log(response.paging.next);
              var x = response.paging.next;
  
              // LOOP THAT PREFERABLY SHOULD CONTINUE UNTIL NO MORE PAGES
              // BUT I WILL DEAL WITH THAT LATER
              for (i = 0; i &lt; 10; i++) {
  
                  // CALLS X WHICH ALSO GIVES ME RHE NEXT PAGE
                  // BUT FOR SOME REASON THE CODE DOES NOT MANAGE TO CHANGE
                  // X AND DO A NEW CALL
                  FB.api(x, function (res){
  
                      console.log(i);
                      console.log(res.paging.next);
                      // HERE I RESPECIFY X
                      x = res.paging.next;
  
                      });
  
                  };
  
             }
  
            ); 
  
      }, {scope: 'publish_actions'});
  </code></pre>