Facebook PHP OAuth2 API,访问令牌无效

时间:2015-12-19 10:39:02

标签: php facebook facebook-graph-api facebook-javascript-sdk oauth2

我收到错误"图表返回错误:无效的OAuth访问令牌"即使我正确设置appId,appSecret,accesstoken。是的,令牌是在Facebook Developer页面中设置的。

<?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();

?>

0 个答案:

没有答案