Fetch Facebook posts using Graph API

前端 未结 1 1560
失恋的感觉
失恋的感觉 2021-01-07 05:38

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

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

相关标签:
1条回答
  • 2021-01-07 06:02

    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!

    0 讨论(0)
提交回复
热议问题