7

I have built a web-based game which submits players' scores to a leaderboard. The game also has a web page which shows the public scores from that leaderboard. It gets this data by hitting the scores.list API end-point. The leaderboard and game have been published in the Google Play Console.

Three players have played the game and their scores have been submitted. All three players have public Play Game profiles and the Leaderboard page in the Play Game Console shows that multiple unique scores have been submitted. But when my Javascript code hits scores.list, only the player's own score is returned in the items collection, not those of the other two players.

How do I get all the scores from the leaderboard?

var request = gapi.client.games.scores.list({
  leaderboardId: leaderboardId,
  collection: 'PUBLIC',
  timeSpan: 'ALL_TIME'
});
request.execute(function(response) {
  if (response.items) {
    response.items.forEach(function(item) {
      // Print item.formattedScore to screen.
      // Only the currently signed-in player's score is returned.
    })
  }
})
Martin Omander
  • 3,223
  • 28
  • 23
  • Upon trying your code, do you have any errors in your error log? – Danee Jul 11 '17 at 11:47
  • No errors from the log, and I have stepped through the code as well in a debugger without seeing any errors. The result.items collection only contains one single entry. That entry is the score of the currently signed-in player. I would have expected one entry in result.items per player who has submitted a score. – Martin Omander Jul 12 '17 at 20:13
  • 2
    The docs say that `The public leaderboard is a leaderboard made up of players who have chosen to share their gameplay activity publicly. If your player has not chosen to share their gameplay activity publicly, they won't appear in this leaderboard.` So you probably need to check that your test users have checked the option to share their gameplay data publicly. – Julien Zakaib Jul 23 '17 at 19:35
  • Probably the only way is to actually send the results to your own server in addition to a _Google the public leaderboard_. – Axalix Jul 23 '17 at 23:27
  • Julien, thanks for your comment. Per your message, I just verified that all players have the `Allow others to see your game activity` option enabled. Their Play Games profiles are also public. I don't know why I'm still not getting all players' scores. – Martin Omander Jul 25 '17 at 03:29

2 Answers2

0

I had wrote some API calls a long time ago, some things to try:

  • Make sure you are not in testing mode (in testing mode it has a different behavior when it comes to shared scores)
  • Set the maxResults parameter just in case (accepted values are 1...30)
MaanooAk
  • 2,418
  • 17
  • 28
  • Thank you for the suggestions! I followed up on both. Testing mode: Made sure the game has been published and is not in testing. maxResults: Set it to 30. Unfortunately I'm still only getting the current player's score... – Martin Omander Jul 27 '17 at 23:52
0

Why are you using result as a variable if you have response as an argument of callback function? I'd suppose everything is fine if you change function(response) to function(result) and the reason this is still working is you have another variable result that stores a single score from one player

Andrew
  • 449
  • 3
  • 7
  • He said it works, but returns only one.. so I guess it's a copy-paste error – MaanooAk Jul 26 '17 at 16:45
  • It would work if there is another `result` variable used to store one score in the parent scope – Andrew Jul 26 '17 at 16:46
  • Oh dear, I made a copy-paste error. Sorry about that. I added the line of code above that assigns the `result` variable. – Martin Omander Jul 26 '17 at 23:45
  • Judging by Google Play API docs there is no property `result` in the response body for request. Try to use bold `response` instead of `response.result`. But it's still confusing how your function is working with the property that does not exist. **Also** Have you tried specifing an optional parameter `maxResults`? Try to set `maxResults: 30` at `request` declaration – Andrew Jul 27 '17 at 06:24
  • Thank you for the note about the `result` variable. I simplified my code by removing it, ran it, and got the same result (only the current player's score is visible). Also, updated the code in the original question above. – Martin Omander Jul 27 '17 at 23:56
  • have you tried to use [listWindow](https://developers.google.com/games/services/web/api/scores/listWindow) method instead of `list`? – Andrew Jul 28 '17 at 06:41