使用Graph API获取Facebook帖子 [英] Fetch Facebook posts using Graph API

查看:103
本文介绍了使用Graph API获取Facebook帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检索此信息并将其显示在我们的网站上?

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

我已经尝试过这个,但没有运气,请帮忙。 / p>

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

推荐答案

该问题与 $。getJSON 有关。 文档指出,请求无法从其他域中成功检索数据,子域名或协议。

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'));

$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>
    


    祝你好运!

    这篇关于使用Graph API获取Facebook帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆