Adam
Adam

Reputation: 44949

How to post a score from the Facebook JavaScript SDK

I want to submit a score from the JavaScript SDK. Here's my current attempt:

FB.api("/me/scores", 'post', {score: seconds, access_token: FB.getSession().access_token}, function(response){
       if (!response || response.error) {
          console.error(response);
       } else {
          console.log(response);
       }
});

I get the error message:

(#15) This method must be called with an app access_token.

Since I am passing the access token, why doesn't this work?

Thanks.

Upvotes: 5

Views: 3000

Answers (2)

Dhiren Patel
Dhiren Patel

Reputation: 645

FB.getSession().access_token will not return an app access token. App access tokens are intended to be used server-side and are retrieved using the app ID and app secret as described here: https://developers.facebook.com/docs/authentication/#applogin.

NOTE: The app secret is like your password; it should never be sent to the client or embedded in client-side code.

Upvotes: 2

ShawnDaGeek
ShawnDaGeek

Reputation: 4150

You need to use an app access_token to update score, which is different from session or user token.

http://developers.facebook.com/docs/authentication/#applogin

2ndly you will need to use the session or user token to read the scores, then use an app token to delete.

http://developers.facebook.com/docs/reference/api/application/#scores

Upvotes: 3

Related Questions