是否可以在Facebook墙上发布应用程序而不是用户?据我所知,应用程序不是Facebook的有效用户,但有很多关于发布为Page而不是用户或应用程序的评论。
如何使用PHP Facebook API进行操作?
答案 0 :(得分:10)
您需要publish_stream,manage_pages
权限。代码类似于:
<?php
// This code is just a snippet of the example.php script
// from the PHP-SDK <https://github.com/facebook/facebook-php-sdk/blob/master/examples/example.php>
require '../src/facebook.php';
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
'appId' => 'app_id',
'secret' => 'app_secret',
));
// Get User ID
$user = $facebook->getUser();
if ($user) {
try {
$page_id = 'page_id';
$page_info = $facebook->api("/$page_id?fields=access_token");
if( !empty($page_info['access_token']) ) {
$args = array(
'access_token' => $page_info['access_token'],
'message' => "I'm a Page!"
);
$post_id = $facebook->api("/$page_id/feed","post",$args);
} else {
$permissions = $facebook->api("/me/permissions");
if( !array_key_exists('publish_stream', $permissions['data'][0]) ||
!array_key_exists('manage_pages', $permissions['data'][0])) {
// We don't have one of the permissions
// Alert the admin or ask for the permission!
header( "Location: " . $facebook->getLoginUrl(array("scope" => "publish_stream, manage_pages")) );
}
}
} 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(array('scope'=>'manage_pages,publish_stream'));
}
// ... rest of your code
?>
我已经撰写了有关此内容的深入教程:How To: Post On Facebook Page As Page Not As Admin User Using PHP-SDK
答案 1 :(得分:4)
您必须首先通过facebook connect进行用户授权,并请求manage_pages权限作为此请求的一部分。您可以使用此权限获取相关页面的令牌和密码。然后,您可以使用这些来授权请求,而不是您为用户收到的令牌/秘密。
查看本页的“页面登录”部分以获取更多信息: http://developers.facebook.com/docs/authentication/