这是PHP的最后一次尝试,如果失败了,我会尝试使用JS.所以我的目标是通过PHP在FB页面上发布"页面名称":这就是我想要的
但我得到的只是如下图所示.此外,它仅对此配置文件可见(不是对喜欢/ etc的朋友/ ppl).
这是我目前的代码
function post_facebook($data=null, $redir = null){
$result = "";
require_once (ROOT. "/apps/configuration/models/ConfigurationItem.php");
require_once (ROOT . "/components/facebook/facebook.php");
$this->ConfigurationItem = new ConfigurationItem($this->getContext());
$row=$this->ConfigurationItem->findByCatKeyItemKey('system','facebook_login');
$apiid=$row['value']; <= Correct apiid
$row=$this->ConfigurationItem->findByCatKeyItemKey('system','facebook_pass');
$secret=$row['value']; <= Correct secret key
$facebook = new Facebook(array(
'appId' => $apiid,
'secret' => $secret,
'cookie' => true,
));
$session = $facebook->getSession();
$me = null;
if ($session) {
try {
$uid = $facebook->getUser();
$me = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
}
$message=$data['facebook_text'];
$attachment = array(
'message' => $data['facebook_text'],
'name' => $data['name'],
'link' => $this->getLinkToLatestNews(),
'description' => '',
);
try {
$facebook->api('/PAGE ID/feed/', 'post', $attachment);
$result = "Facebook: Sent";
} catch (FacebookApiException $e) {
$result = "Facebook: Failed";
error_log($e);
}
} else {
$login_url = $facebook->getLoginUrl();
header("Location: ".$login_url);
exit;
}
echo $result;
exit;
//return $result;
}
Run Code Online (Sandbox Code Playgroud)
我做错了什么?我在API文档/顶级谷歌搜索结果中找不到任何内容,仅适用于JS.感谢帮助!
njo*_*den 20
您需要确保为用户请求'manage_pages'权限.一旦你得到了,你可以做$facebook->api('/me/accounts')
,你会收到一个令牌回来,你可以用它来发布在页面上(与页面信息一起)的页面.