1

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?

Moon
  • 22,195
  • 68
  • 188
  • 269

3 Answers3

5

app access_token you can simple make it like this:

$facebook->api('/me/scores', 'POST', array( 'score' => 100, 'access_token' => $facebook->getAppId().'|'.$facebook->getApiSecret() ));

voila

cojack
  • 2,444
  • 1
  • 17
  • 18
2

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);
ifaour
  • 38,035
  • 12
  • 72
  • 79
  • 1
    // ah..yes! that was the problem. Is it possible to get an Application token using facebook php sdk? stackoverflow is deleting @ifaour somehow... – Moon Oct 19 '11 at 19:06
  • Well, I'm not sure if granting the `manage_pages` and then calling `me/accounts` and getting the app `access_token` would be the same, but that would be so much work just for this. What do you mean by your last sentence? – ifaour Oct 19 '11 at 19:23
  • // i appreciate your answers. Ah...disregard my last sentence...I used "@ifaour", but stackoverflow keeps removing it from my comment. – Moon Oct 19 '11 at 19:28
  • 1
    by the way..your website is veeerrrrry helpful. – Moon Oct 19 '11 at 19:34
  • @Moon thanks! There will be a lot of changes and tutorials coming soon! – ifaour Oct 19 '11 at 19:39
2
$ret_obj = $fb->api( '/' . $fb->getUser() . '/scores', 'POST', array(
    'score' =>  100,
    'access_token' => $fb->getAppId().'|'.$fb->getApiSecret()
));

If you specify the app access token in the access_token parameter, you will eventually lose the ability to use /me, so you have to be specific about the user ID. Otherwise you get this error: "OAuthException: An active access token must be used to query information about the current user", as explained here : facebook Uncaught OAuthException: An active access token must be used to query information about the current user

Community
  • 1
  • 1
ydubois
  • 21
  • 1