必须使用活动访问令牌来查询有关当前用户的信息 &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 FacebookFacebook([
  'app_id' => '1501716620042981',
  'app_secret' => '510d15193610ca682b7f79c156992bb5',
  'default_graph_version' => 'v2.3',
  ]);
$helper = $fb->getRedirectLoginHelper();

try {
  $accessToken = $helper->getAccessToken();
} catch(FacebookExceptionsFacebookResponseException $e) {
  // When Graph returns an error
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(FacebookExceptionsFacebookSDKException $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']

相关内容

  • 没有找到相关文章

最新更新