Get Facebook Posts Using Graph API

How to get this information and show it on our website?

I tried this one , but no luck, please help.

+2
source share
1 answer

The problem is with $.getJSON . As stated in the documentation , the request cannot successfully retrieve data from another domain, subdomain, or protocol.

I don’t see that you mentioned the language you want to use to receive these messages, but here are two simple examples of how to do this 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

+4
source

All Articles