张贴为页面而不是个人用facebook php sdk 5.0.0

时间:2015-09-01 20:54:13

标签: php facebook facebook-graph-api sdk

我为此搜索过,我得到的'答案'已经过时了。无论何时我运行脚本,它都会将带有我的个人资料的消息发布到Facebook页面,即使我有管理员权限。 这是我正在使用的代码

<?
require_once __DIR__ . '/Facebook/autoload.php';
session_start();

$fb = new Facebook\Facebook([
'app_id' => '',
'app_secret' => '',
'default_graph_version' => 'v2.4'
]);
$page_id="";
$accessToken='Access token I got from https://developers.facebook.com/tools/explorer/145634995501895/';


// Sets the default fallback access token so we don't have to pass it to each request
$fb->setDefaultAccessToken('');

try {
  $response = $fb->get('/me');
  $userNode = $response->getGraphPage();
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
 echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}

echo 'Logged in as ' . $userNode->getName();



?>

0 个答案:

没有答案