我正在嘗試將帖子發佈到Facebook頁面,但是作爲頁面 - 而不是我自己的Facebook配置文件。我正在使用Facebook PHP SDK的第5版。任何想法如何實現這一目標?我的下面的代碼發佈到Facebook頁面沒問題,但它將消息發佈爲我自己的配置文件而不是頁面。發佈到Facebook頁面,因爲該頁面不是管理員用戶
session_start();
define('FACEBOOK_SDK_V4_SRC_DIR', __DIR__ . '/src/facebook-sdk-v5/');
require_once __DIR__ . '/src/facebook-sdk-v5/autoload.php';
$fb = new Facebook\Facebook([
'app_id' => 'appid',
'app_secret' => 'secretid',
'default_graph_version' => 'v2.2',
]);
$helper = $fb->getRedirectLoginHelper();
try {
$accessToken = $helper->getAccessToken();
} 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;
}
if (isset($accessToken)) {
$_SESSION['facebook_access_token'] = (string) $accessToken;
$linkData = [
'link' => 'http://www.example.com',
'message' => 'User provided message',
];
try {
$response = $fb->post('/294673057366719/feed', $linkData, $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();
echo 'Posted with id: '.$graphNode['id'];
} else {
$permissions = ['publish_pages', 'manage_pages'];
$loginUrl = $helper->getLoginUrl('http://app.co.uk:8888/facebook/', $permissions);
echo '<a href="'.$loginUrl.'">Log in</a>';
}