我想使用 PHP 作为页面发布到 facebook 页面墙。我通过下面的链接获得了access_token。
https://graph.facebook.com/oauth/authorize?type=user_agent&client_id=123456789&redirect_uri=http%3A%2F%2Fmysite.net&scope=publish_stream,manage_pages,offline_access
https://graph.facebook.com/me/accounts?access_token=...
我正在使用这个简单的代码:
$appid = "";
$secret = "";
$pageid = "";
$access_token = "";
require_once("facebook-php-sdk/src/facebook.php");
$facebook = new Facebook(array(
'appId' => $appid,
'secret' => $secret
));
try {
$args = array(
'access_token' => $access_token,
'message' => 'Test',
'link' => 'http://www.test.com',
'description' => 'Test'
);
$post_id = $facebook->api("/$pageid/feed","post",$args);
} catch (FacebookApiException $e) {
error_log($e);
}
这就是我收到的错误:
OAuthException: (#200) Posts where the actor is a page cannot also include a target_id
但发布 /me/feed 也不起作用。我用谷歌搜索到的所有解决方案都不再起作用,官方文档也没有帮助。当我以用户(而不是页面)身份发布并使用 javascript api(用户需要“共享”点击操作)时,我得到了它的工作。
有人知道自动发布到 Facebook 页面作为页面的解决方案吗?花了几天时间试图弄清楚-_-
Thanks,
A.