使用图谱API从fb获取最新帖子

问题描述:

我想从fb获取最新帖子,并且需要显示在我的网站上(magento).我已经在Facebook中注册了一个应用,并尝试使用url来获取帖子,但是它给出了空数组

I want to get latest posts from fb and need to display on my site(magento). I have registerd one app in facebook and try to getting posts by using the url but it's giving empty array

    require_once(Mage::getBaseDir('lib') . '/facebook/facebook.php');
    $facebook = new Facebook(array(
              'appId'  => 'xxxxxxxxxxxx',
              'secret' => 'xxxxxxxxxxxxxxxxxxxx',
            ));
    $fbid = "xxxxxxxxxx";
    $secret = "xxxxxxxxxxxxxxxxxxxxxxx";
    $token = 'https://graph.facebook.com/oauth/access_token?client_id='.$fbid.'&client_secret='.$secret.'&grant_type=client_credentials';
    $token = file_get_contents($token);
    $posts = json_decode(
                file_get_contents('https://graph.facebook.com/' . $fbid . '/feed?
                    access_token=' . $token
                )
            );

但是它给出了一个空数组,你能帮我得到结果以及为什么它给出空吗?

But it's giving an empty array and could you help me to get the results and why it is giving empty?

为了从Facebook读取Feed,必须将用户登录到Facebook并要求用户提供read_stream权限.

In order to read the Feed from Facebook, you must log the user into Facebook and ask the user for the read_stream permission.

该供稿将是登录用户的供稿,可能不适用于您网站的所有用户,除非您网站的每个用户看到自己的供稿...

The feed will be the logged-in user's feed and may not be appropriate for all users of your website, unless each user of your website sees their own feed...