[英]Facebook PHP SDK V5 - Get Page Access Token Not User Access Token
I am trying to figure out how to post to a Facebook fan page as the "voice of the page" as Facebook calls it.我想弄清楚如何将 Facebook 粉丝页面作为 Facebook 所称的“页面声音”发布到 Facebook 粉丝页面。
I have the following code:我有以下代码:
$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();
When this runs I get the error:当它运行时,我收到错误:
Graph returned an error: Unsupported post request.
From what I understand, I need to access the page token that I am trying to post to?据我了解,我需要访问我要发布到的页面令牌? How can I do this?
我怎样才能做到这一点? Please help!
请帮忙!
You need to get a page access token too, here's how to do it.您还需要获得一个页面访问令牌,这是如何做到的。 It will give you a list of all your pages with their corresponding access tokens.
它将为您提供所有页面及其相应访问令牌的列表。
https://developers.facebook.com/docs/facebook-login/access-tokens#pagetokens https://developers.facebook.com/docs/facebook-login/access-tokens#pagetokens
The "Unsupported post request" could also mean that your application is in testing mode still. “不支持的发布请求”也可能意味着您的应用程序仍处于测试模式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.