我在facebook上创建了一个应用程序,在php sdk之间,我可以在我的个人资料上发布我的网站文章。
现在,我想在我的粉丝页面发布我的文章,而不是在我的prfile中。我怎么能这样做?
这是我使用的代码,与facebook开发人员中的示例差别不大:
// Remember to copy files from the SDK's src/ directory to a
// directory in your application on the server, such as php-sdk/
require_once('facebook.php');
$config = array(
'appId' => 'xxxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxxx',
);
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
?>
<?
if($user_id) {
// We have a user ID, so probably a logged in user.
// If not, we'll get an exception, which we handle below.
try {
$access_token = $facebook->getAccessToken();
$page_id='xxxxxxxxxxxxxx';
$ret_obj = $facebook->api('/me/feed', 'POST',
array(
'link' => $link,
'message' => $titolo,
'picture' => 'http://xxxxxxxxxxxxxxxxxx',
'name' => 'Ecosport',
'access_token' => $access_token
));
echo '<pre>Post ID: ' . $ret_obj['id'] . '</pre>';
} catch(FacebookApiException $e) {
// If the user is logged out, you can have a
// user ID even though the access token is invalid.
// In this case, we'll get an exception, so we'll
// just ask the user to login again here.
$login_url = $facebook->getLoginUrl( array(
'scope' => 'publish_stream'
));
header("location:$login_url");
error_log($e->getType());
error_log($e->getMessage());
}
// Give the user a logout link
$id_articolo=$_GET['id_articolo'];
header("location:xxxxxxxxxx");
/*echo '<br /><a href="' . $facebook->getLogoutUrl() . '">logout</a>';*/
} else {
// No user, so print a link for the user to login
// To post to a user's wall, we need publish_stream permission
// We'll use the current URL as the redirect_uri, so we don't
// need to specify it here.
$login_url = $facebook->getLoginUrl( array( 'scope' => 'publish_stream' ) );
header("location:$login_url");
/*echo 'Please <a href="' . $login_url . '">login.</a>';*/
}
?>
Oviusly“xxxx”用于隐私。我绑定将“$ facebook-&gt; api('/ me / feed',......”更改为此“$ facebook-&gt; api('/ $ page_id / feed',..... ..“但没有。我不能在我的粉丝页面发表我的文章。
你能帮助我吗?
非常感谢。
答案 0 :(得分:0)
您需要获得manage_pages
和publish_stream
权限。然后拨打/ me / accounts以获取用户管理的帐户列表(也称为页面)。该帐户列表中的每个帐户都有一个与之关联的访问令牌。该访问令牌是特殊的,需要用于新建facebook api的实例。一旦你这样做,发布到页面墙就像发布到用户的墙(即/ me / feed)