Kris Lipscombe
Kris Lipscombe

Reputation: 11

Retrieving scores with Application Token

So I have an app set up, and I'm trying to send scores via a server rather than from the application. This allows me to keep scores longer term, whilst also having the social advantages of Facebook.

Now, the problem I have comes in retrieving the scores using the Application Token. I can post absolutely fine using either the Application Token or a User Token, but when retrieving the scores with the Application Token I receive the following:

{
  "data": [
  ]
}

If it was flat out not working or a permissions issue I'd expect to receive an error returned, but the fact it returns an empty array is puzzling. More puzzling is that using a User Access Token retrieves the score absolutely fine, so it's clearly arriving correctly into the Facebook backend.

Is this just a problem with using an App Access Token in this situation? The documentation says that I should be able to use one, but maybe it's mistaken?

I'd also like to clarify that I've run this both in code and via the Graph Explorer, always with no success.

Upvotes: 1

Views: 719

Answers (2)

Dasu
Dasu

Reputation: 433

Make sure that you have granted user_games_activity and friends_games_activity permissions on developers.facebook.com/tools/explorer from above link you will get an application access_token and add it in your code like this

public void sendDataToFacebookGraphServer()
    {

            // TODO Auto-generated method stub
            final Session session = Session.getActiveSession();

             List<String> permissions = session.getPermissions();
                if (!isSubsetOf(PERMISSIONS, permissions)) {

                    Session.NewPermissionsRequest newPermissionsRequest = new Session
                            .NewPermissionsRequest(UnityPlayer.currentActivity, PERMISSIONS);
                session.requestNewPublishPermissions(newPermissionsRequest);
                    return;
                }
            HttpClient client = new DefaultHttpClient();            
            HttpPost post = new HttpPost("https://graph.facebook.com/user_id/scores");
            List<NameValuePair> pairs = new ArrayList<NameValuePair>();
            pairs.add(new BasicNameValuePair("score", "3000")); 
                   // add this line and try             
                   pairs.add(new BasicNameValuePair("access_token", "add_app_access_token_here"));

            try{
                post.setEntity(new UrlEncodedFormEntity(pairs));
            }
            catch(UnsupportedEncodingException e)
            {

            }
            try{            
                response = client.execute(post);

                Log.i("*********Response*******************************************************", response.toString());
                UnityPlayer.currentActivity.runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        // TODO Auto-generated method stub
                        Toast.makeText(UnityPlayer.currentActivity,""+response.toString(),Toast.LENGTH_LONG).show();
                    }
                });

            }
            catch (IOException e1) 
            {

            }


}

Upvotes: 1

Igy
Igy

Reputation: 43816

Is this supposed to work with the app access token? I don't think it is.

According to the Scores Documentation you can

  • Retrieve a user's score with the user or app access token (/USER_ID/scores)
  • Retrieve a user's friends' scores for your app with the user access token (/APP_ID/scores)
  • Retrieve a user's friends' scores in any app with the user access token (/USER_ID/scores) - though this one respects those users' privacy settings so you won't get an answer for users whose game/app activity is private

Upvotes: 0

Related Questions