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.

4

0 回答 0