必须使用活动访问令牌来查询有关当前用户的信息.oautheexception [code] =>2500.


An active access token must be used to query information about the current user & OAuthException [code] => 2500

当用户访问令牌时,我得到错误喜欢。请立即帮助我。我该如何解决这个问题,告诉我

stdClass Object ([error] => stdClass Object ([message] =>一个活动对象访问令牌必须用于查询当前用户的信息。[type] => OAuthException [code] => 2500))

require 'facebook-php-sdk-v4/src/Facebook/autoload.php';
require("facebook.php");
$fb = new Facebook'Facebook([
  'app_id' => '1501716620042981',
  'app_secret' => '510d15193610ca682b7f79c156992bb5',
  'default_graph_version' => 'v2.3',
  ]);
$helper = $fb->getRedirectLoginHelper();

try {
  $accessToken = $helper->getAccessToken();
} 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;
}
if (isset($accessToken)) {
  // Logged in!
 echo $_SESSION['facebook_access_token'] = (string) $accessToken;
  // Now you can redirect to another page and use the
  // access token from $_SESSION['facebook_access_token']
} 

     $curl_handle=curl_init();
    curl_setopt($curl_handle, CURLOPT_URL,'https://graph.facebook.com/me/?fields=albums.fields(id,name,cover_photo,photos.fields(name,picture,source)),videos.type(uploaded)&'.$_SESSION['facebook_access_token']);
    curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
    curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl_handle, CURLOPT_USERAGENT, 'fb');
    curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
    # Return response instead of printing.
    $query = curl_exec($curl_handle);
    curl_close($curl_handle);

    print_r(json_decode($query));

您没有以正确的方式提供访问令牌。它应该表示为access_token URL查询参数的值,如下所示:

'https://graph.facebook.com/me/?fields=albums.fields(id,name,cover_photo,photos.fields(name,picture,source)),videos.type(uploaded)&access_token='.$_SESSION['facebook_access_token']

为清晰,不包含特定字段:

'https://graph.facebook.com/me?access_token='.$_SESSION['facebook_access_token']