我有一个网站和一个网站的facebook页面。在大多数新闻更新中,我都会将它们发布在facebook页面的墙上。
现在我想在我的网站上显示该facebook页面的内容,就像启用了“流”的facebook的like Box一样:http://developers.facebook.com/docs/reference/plugins/like-box/
但是,我只想显示流,并且可以在我自己的演示文稿中完美地显示它。那么,通过facebook的API只获取facebook页面的内容是可能的吗?
发布于 2011-09-09 20:41:30
我认为如果你使用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查看页面的帖子/提要,这让我认为你需要用户登录facebook……我对此相当陌生,但您应该了解如何获取访问令牌,因为您需要一个访问令牌。
https://stackoverflow.com/questions/7361733
复制相似问题