php - An active access token must be used to query information about the current user


I have defined an access token. It is a fresh access token obtained with curl. Why am I still getting the error: An active access token must be used to query information about the current user.


define('YOUR_APP_ID', '*****');
define('YOUR_APP_SECRET', '*****');

function get_facebook_cookie($app_id, $app_secret) {
  $args = array();
  parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args);
  $payload = '';
  foreach ($args as $key => $value) {
    if ($key != 'sig') {
      $payload .= $key . '=' . $value;
  if (md5($payload . $app_secret) != $args['sig']) {
    return null;
  return $args;

$cookie = get_facebook_cookie(YOUR_APP_ID, YOUR_APP_SECRET);

$url = "";
$client_id = "214620421927216";
$client_secret = "1dc2110b1cdbbdf8604edc4ee7b03b81";
$postString = "client_id=$client_id&client_secret=$client_secret&type=client_cred";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_FAILONERROR, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postString);
$response = curl_exec($curl);
echo "</br>";

$access_token = substr($response,13);
echo $access_token;
echo "</br>";

$url = '' . $access_token;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);

$user = json_decode($response);

        <?php if ($cookie) { ?>
      Welcome <?php  ?>
    <?php } else { ?>
    <?php } ?>
    <div id="fb-root"></div>
    <script src=""></script>
      FB.init({appId: '<?= YOUR_APP_ID ?>', status: true,
               cookie: true, xfbml: true});
      FB.Event.subscribe('auth.login', function(response) {



the token that you tried to get in the above is the app level access token. in order to query "/me" via graph api, you need to get user access token.

check the user login section in FB doc:

People are also looking for solutions to the problem: mysql - Jquery/PHP ajax login system


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.