facebook:在网站上加载facebook页面的墙内容

时间:2011-09-09 12:36:48

标签: facebook fbml xfbml

我有一个网站和网站的Facebook页面。对于大多数新闻更新,我将它们发布在Facebook页面的墙上。

现在我想在我的网站上显示该Facebook页面的内容,就像启用了“流”的facebook的Like Box一样:http://developers.facebook.com/docs/reference/plugins/like-box/

但是,我只想显示流,完全可以在我自己的演示文稿中显示它。那么有可能只通过facebook的API获取Facebook页面的内容吗?

1 个答案:

答案 0 :(得分:2)

我认为如果您使用SDK,可以使用

获取它
fb->api("/{id}/feed");

有一个php和一个javascript sdk。

但您现在还需要一个访问令牌来获取页面的提要。

编辑:以下是为您的目的而修改的example.php(来自php-sdk)的副本。

include_once("facebook-sdk/facebook.php");

// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
  'appId'  => 'APP_ID GOES HERE',
  'secret' => 'SECRET GOES HERE',
));

// Get User ID
$user = $facebook->getUser();

// We may or may not have this data based on whether the user is logged in.
//
// If we have a $user id here, it means we know the user is logged into
// Facebook, but we don't know if the access token is valid. An access
// token is invalid if the user logged out of Facebook.

if ($user) {
  try {
    // Proceed knowing you have a logged in user who's authenticated.

    // This is where we grab the posts
    $wall_posts = $facebook->api('/courseyou/posts');
  } catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
  }
}

// Login or logout url will be needed depending on current user state.
if ($user) {
  $logoutUrl = $facebook->getLogoutUrl();
} else {
  $loginUrl = $facebook->getLoginUrl();
}
?>


<?php if ($user): ?>
<a href="<?php echo $logoutUrl; ?>">Logout</a>
<?php else: ?>
<div><a href="<?php echo $loginUrl; ?>">Login with Facebook</a></div>
<?php endif ?>

<h3>Wall Posts</h3>
<?php
foreach ($wall_posts["data"] as $post) {
    echo "<p>".$post["from"]["name"].": ".$post["message"]."</p>";
}
?>

据我所知,你需要一个访问令牌来查看api的页面帖子/ feed,这让我觉得你需要用户登录facebook ....我对此很新,但是您应该研究如何获取访问令牌,因为您需要一个访问令牌。