Search code examples
phpfacebookfacebook-graph-apicurl

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


I trying to get a Facebook cover by run

curl https://graph.facebook.com/me/?fields=cover?access_token=*****

In my terminal - I kept getting

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

Here is my code:

public function feed(){

    $id =  Auth::user()->account_id;
    $token_oauth = DB::table('tokens')->where('account_id','=',$id)->first();
    $token = $token_oauth->oauth;
    $url = 'https://graph.facebook.com/me/feed?access_token='.$token;
    $data = shell_exec('curl '.$url);
    $raw = json_decode($data,true);
    return $raw;

}

It works. It return list of feed. Then I followed the same steps for my cover photo.

public function cover(){

    $id =  Auth::user()->account_id;
    $token_oauth = DB::table('tokens')->where('account_id','=',$id)->first();
    $token = $token_oauth->oauth;

    $url = 'https://graph.facebook.com/me?fields=cover&access_token='.$token;
    $data = shell_exec('curl '.$url);
    $raw = json_decode($data,true);
    return $raw;
}

It return

{"error":{"message":"An active access token must be used to query information about the current user.","type":"OAuthException","code":2500,"fbtrace_id":"AOkTdE\/rYNW"}}

Solution

  • This would be correct, the Access Token was valid but you wrote "?" instead of "&" for the second parameter:

    https://graph.facebook.com/me/?fields=cover&access_token=*****
    

    Btw, you can check if your Token is valid in the Debugger: https://developers.facebook.com/tools/debug/