Facebook Graph API PHP SDK在页面上发布页面 [英] Facebook Graph API PHP SDK posting on page as page
问题描述
这是PHP的最后一次尝试,如果失败了,我会尝试使用JS。所以我的目标是通过PHP在FB页面上发布页面名称:这是我想要获得的
It's final try with PHP, if it fails, I'll try with JS. So my goal is to post on FB page as "Page name" through PHP: this is what I want to get
但是我得到的都是下面的图片。此外,只有这个配置文件可见(不适用于/ etc等)的朋友/ ppl。
But all I get is shown pic below. Also, it's visible ONLY to this profile (not to friends/ppl who like/etc.).
这是我目前的代码
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;
}
我做错了什么?我在API文档/顶级Google搜索结果中找不到任何内容,仅适用于JS。感谢您的帮助!
What I'm doing wrong? I couldn't find anything in API documentation/top google results, only for JS. Thanks for help!
推荐答案
您需要确保您为用户请求manage_pages权限。一旦你得到了,你可以做 $ facebook-> api('/ me / accounts')
,你会收到一个令牌(连同页面信息),您可以使用该页面作为页面。
You'll need to make sure you're requesting the 'manage_pages' permission for the user. Once you've got that you can do $facebook->api('/me/accounts')
and you'll receive a token back (along with the page info) that you can use to post on the page as the page.
这篇关于Facebook Graph API PHP SDK在页面上发布页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!