即使我正确设置了 appId、appSecret、accesstoken,我也会收到错误消息“Graph returned an error: Invalid OAuth access token”。是的,令牌是在 Facebook 开发者页面中设置的。
<?php
session_start();
require_once ('data/Facebook/autoload.php');
$fb = new Facebook\Facebook([
'app_id' => 'xxxxxxxxxxx',
'app_secret' => 'xxxxxxxxxxxx',
'default_graph_version' => 'v2.5'
]);
try {
$response = $fb->get('/me','xxxxxxxxxxx');
}
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;
}
$me = $response->getGraphUser();
echo 'Logged in as ' . $me->getName();
?>