Jeaf Gilbert
Jeaf Gilbert

Reputation: 12021

Fetch Facebook posts using Graph API

How to retrieve this information and show it in our website?

I've tried this but no luck, please help.

Upvotes: 2

Views: 2470

Answers (1)

misterjinx
misterjinx

Reputation: 2616

The problem is related to $.getJSON. As the documentation states, the request can not successfully retrieve data from a different domain, subdomain, or protocol.

I don't see you mention a language you want to use in order to get those posts, but here are 2 simple examples of how to do it using:

  • PHP:

$info = json_decode(file_get_contents('https://graph.facebook.com/cocacola/posts'));

if ($info) {
    foreach ($info->data as $obj) {
        echo $obj->message, "<br/>";
    }   
}
  • javascript:
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script type="text/javascript">
FB.api('/cocacola/posts', function(response) {
    for (var i = 0; i < response.data.length; i++) {
        alert(response.data[i].message);
    }
});
</script>

Good luck!

Upvotes: 4

Related Questions