ANB_Seth
ANB_Seth

Reputation: 141

facebook app: getting scores from friends

this is my first post and im close to a breakdown! Im trying to figur this out for 2 days already and im not sure what I'm doing wrong, and I can't find an answer anywhere.

I'm coding a facebook game and want to store the "scores" for its users. Kinda simple I thought. For this I have two user-accounts playing the app. So far I am able to GET and POST the score for the logged in user. However I cannot find a way to GET the scores of his friend(s). In the Facebook dev description it states that the ("uid/scores") request should return both, scores from the user and its friends, but it doesnt. Also trying "friend-ID/scores", aswell as "friend-ID?field=scores" wont return anything more than:

{
  "data": [
  ]
}

I tried nearly all combinations of app-permissions, poking around in the Graph-API-explorer with wild combinations of app_token and access_token requests, user-id and app-id, but nothing comes of it. The data returned is always empty.

What am I doing wrong? What permissions does my APP need so I can GET my friends score for my app(game)? Is it because the game is still in developement/not approved yet? What graph command do I have to send? Has anybody been successfull with getting friends scores?

thanks in advance! :-)

Upvotes: 0

Views: 3890

Answers (2)

efeyc
efeyc

Reputation: 2130

You can make a request to "APP_ID/scores" which will return the scores of the current user and his friend's scores

(result:, [data: (
        {
        application =         {
            id = APP_ID;
            name = APP_NAME;
            namespace = APP_NAMESPACE;
        };
        score = 639;
        user =         {
            id = USERID of user A;
            name = "User A";
        };
    },
        {
        application =         {
            id = APP_ID;
            name = APP_NAME;
            namespace = APP_NAMESPACE;
        };
        score = 205;
        user =         {
            id = USERID of user B;
            name = "User B";
        };
    },
        {
        application =         {
            id = APP_ID;
            name = APP_NAME;
            namespace = APP_NAMESPACE;
        };
        score = 100;
        user =         {
            id = USERID of user C;
            name = "User C";
        };
    }
)])

Upvotes: 0

James Pearce
James Pearce

Reputation: 2332

The documentation at https://developers.facebook.com/docs/reference/api/user/ states that, indeed, /scores returns scores for the user assuming they granted you the user_games_activity permission.

You only need a user access token for that, and it should return something like:

{
  "data": [
    {
      "user": {
        "name": "James Pearce", 
        "id": "738229837"
      }, 
      "score": 20, 
      "application": {
        "name": "Bubble Safari", 
        "namespace": "bubblesafari", 
        "id": "164731003644283"
      }
    },
    ...

It doesn't itself return the score for the user's friends: to get that you would need to do a separate call to /[friend_id]/scores (assuming the first user had granted you friends_games_activity).

Assuming you have the right permissions (checked using /me/permissions), an empty array means that the friend either has no scores or has chosen not to share them.

There is no way to retrieve a list of scores for all users of an app, even with the app access token.

Upvotes: 1

Related Questions