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

时间:2015-07-11 04:54:40

标签: php facebook-graph-api-v2.3

当用户访问令牌时,我收到错误就像。 请马上帮助我。我怎么能解决这个问题,告诉我

  

stdClass对象([error] => stdClass对象([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));

1 个答案:

答案 0 :(得分:7)

您未以正确的方式提供访问令牌。它应显示为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']