我正在试图弄清楚如何将Facebook粉丝页面发布为Facebook称之为“页面的声音”。
我有以下代码:
$fb = new Facebook\Facebook([
'app_id' => '17xxxxxxxxxx',
'app_secret' => 'exxxxxxxxxx',
'default_graph_version' => 'v2.4',
]);
$helper = $fb->getRedirectLoginHelper();
try {
$accessToken = $helper->getAccessToken();
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// There was an error communicating with Graph
echo $e->getMessage();
exit;
}
if (isset($accessToken)) {
// User authenticated your app!
// Save the access token to a session and redirect
$_SESSION['facebook_access_token'] = (string) $accessToken;
// Log them into your web framework here . . .
// Redirect here . . .
print_r($accessToken);
//// get following data from the db or just replace them ////
$params["message"] = $title;
$params["link"] = $targetUrl;
$params["picture"] = $imgUrl;
$params["description"] = $description;
// post to Facebook
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->post('/229101234342377163/feed', $params, $accessToken);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$graphNode = $response->getGraphNode();
当这个运行时我得到错误:
Graph returned an error: Unsupported post request.
根据我的理解,我需要访问我要发布的页面令牌?我怎样才能做到这一点?请帮忙!
答案 0 :(得分:-1)
您还需要获取页面访问令牌,这里有如何操作。它会为您提供所有页面的列表及其相应的访问令牌。
https://developers.facebook.com/docs/facebook-login/access-tokens#pagetokens
"不支持的帖子请求"也可能意味着您的应用程序仍处于测试模式。