简体   繁体   中英

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.

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM