0

I am trying to get facebook feed data for a particular user. I can get using php code

$pageFeed = $facebook->api("/me/feed",array('access_token' => $facebook->getAccessToken(),'limit'=>5));

I got a response like below,

Array
(
    [data] => Array
        (
                .....feed data...
        )
    [paging] => Array
        (
            [previous] => https://graph.facebook.com/xxxxxxx/feed?limit=5&since=1347771792&__previous=1
            [next] => https://graph.facebook.com/xxxx/feed?limit=5&until=1347642062
        )

)

Later I found https://developers.facebook.com/blog/post/478/ to paginate feed data using javascript. In the following code I tried

<html>
<body onload="loadPosts()">
  <div id="fb-root"></div>
  <script>
    var graphURL = "https://graph.facebook.com/testname/posts?" +
                     "callback=processResult&access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&limit=10";

    // Use JSONP to call the Graph API
    function loadPosts() {
      var script = document.createElement("script");
      script.src = graphURL;
      document.body.appendChild(script);
    }

    function processResult(posts) {
      if (posts.paging == undefined) {
        document.getElementById("loadMore").innerHTML =
          "No more results";
      }
      else {
        graphURL = posts.paging.next;
        for (var post in posts.data) {
          var message = document.createElement("div");
          message.innerHTML = posts.data[post].message;
          document.getElementById("content").appendChild(message);
        }
      }
    }
  </script>
  <div id="content"></div>
  <button id="loadMore" onclick="loadPosts()">Load more</button>
</body>
</html>

When I run the javascript code I always get undefined as a result and I could not get next set of result when clicked load more button.

How do I get the next set of facebook data using php or javascipt? I tried both but I was not able to find the solution yet.

Please give some advice.

Thanks in advance.

Havelock
  • 6,913
  • 4
  • 34
  • 42
mymotherland
  • 7,968
  • 14
  • 65
  • 122
  • Hmm, I do not think it is possible – Derfder Sep 16 '12 at 06:35
  • Any specific reason you are not using the official JavaScript SDK? – Lix Sep 16 '12 at 06:35
  • possible duplicate of [How does paging in facebook javascript API works?](http://stackoverflow.com/questions/5023757/how-does-paging-in-facebook-javascript-api-works) – Lix Sep 16 '12 at 06:40
  • @Lix No reason...I need solution to paginate next set of result... – mymotherland Sep 16 '12 at 06:41
  • Use the SDK - it will be much easier. Take a look at the pagination documentation from facebook - https://developers.facebook.com/docs/reference/api/pagination/ – Lix Sep 16 '12 at 06:43

0 Answers0