Players only get their own scores from scores.list API
Asked Answered
C

2

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.
    })
  }
})
Classified answered 10/7, 2017 at 22:51 Comment(5)
Upon trying your code, do you have any errors in your error log?Electromagnetism
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.Classified
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.Execratory
Probably the only way is to actually send the results to your own server in addition to a Google the public leaderboard.Anthropoid
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.Classified
T
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)
Tolmach answered 25/7, 2017 at 15:32 Comment(1)
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...Classified
N
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

Nord answered 26/7, 2017 at 16:37 Comment(6)
He said it works, but returns only one.. so I guess it's a copy-paste errorTolmach
It would work if there is another result variable used to store one score in the parent scopeNord
Oh dear, I made a copy-paste error. Sorry about that. I added the line of code above that assigns the result variable.Classified
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 declarationNord
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.Classified
have you tried to use listWindow method instead of list?Nord

© 2022 - 2024 — McMap. All rights reserved.