Search code examples
phpfacebookfacebook-graph-api

How to solve 'This method must be called with an app access_token' error?


I'm testing out scores api on my test app.

So...I've singed up my app with the following permissions.

publish_stream,
publish_actions,
user_status,
user_photos

After logged in, I'm requesting the following api in PHP

$loggedUser = $Facebook->getUser();
$scoreUpdate = $Facebook->api('/'.$loggedUser."/scores", 'post', array('score'=> 100));

I get the following error.

This method must be called with an app access_token

So I've checked what the sdk is sending to facebook, and I've confirmed that it is sending 'access_token' along with my params.

What's the problem in this case?


Solution

  • Now there are two tokens, a User token...and an Application token. You need the later.

    Now the PHP-SDK will append the user access_token if it finds one which is I think your case. I suggest you read the official Facebook how-to for publishing scores

    Example taken from my tutorial:

    $APPLICATION_ID = "APP_ID";
    $APPLICATION_SECRET = "APP_SECRET";
    
    $token_url =    "https://graph.facebook.com/oauth/access_token?" .
                    "client_id=" . $APPLICATION_ID .
                    "&client_secret=" . $APPLICATION_SECRET .
                    "&grant_type=client_credentials";
    $app_token = file_get_contents($token_url);