I had add 10 google play leaderboards in my libgdx app. Now I want to get player's rank from each leaderboards. I use this function:
private void loadRankOfLeaderBoard(final int level) {
Games.Leaderboards.loadCurrentPlayerLeaderboardScore(_gameHelper.getApiClient(), getResources(). getString(LEADER_BOARDS.get(level-1)), LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_PUBLIC).setResultCallback(new ResultCallback<Leaderboards.LoadPlayerScoreResult>() {
@Override
public void onResult(Leaderboards.LoadPlayerScoreResult scoreResult) {
if(isScoreResultValid(scoreResult)){
rank.add(level-1, (int)scoreResult.getScore().getRank());
Log.d("COUCOU", "isScoreResultValid "+(level));
}
else{
rank.add(level-1, -1);
Log.d("COUCOU", "NOTisScoreResultValid "+(level) + " GamesStatusCodes." + (scoreResult.getStatus().getStatusMessage()));
}
}
});
}
private boolean isScoreResultValid(Leaderboards.LoadPlayerScoreResult scoreResult) {
return scoreResult != null && GamesStatusCodes.STATUS_OK == scoreResult.getStatus().getStatusCode() && scoreResult.getScore() != null;
}
and I use it in the onCreate like this:
GameHelperListener gameHelperListener = new GameHelper.GameHelperListener(){
@Override
public void onSignInSucceeded(){
for(int i = 0; i < LEADER_BOARDS.size(); i++){
loadRankOfLeaderBoard(i+1);
}
}
@Override
public void onSignInFailed(){
}
};
_gameHelper.setup(gameHelperListener);
And the Log result is that:
06-30 21:59:01.216: D/COUCOU(21238): isScoreResultValid 1
06-30 21:59:01.703: D/COUCOU(21238): isScoreResultValid 2
06-30 21:59:02.147: D/COUCOU(21238): isScoreResultValid 3
06-30 21:59:02.370: D/COUCOU(21238): NOTisScoreResultValid 4 GamesStatusCodes.STATUS_NETWORK_ERROR_NO_DATA
06-30 21:59:02.584: D/COUCOU(21238): NOTisScoreResultValid 5 GamesStatusCodes.STATUS_NETWORK_ERROR_NO_DATA
06-30 21:59:02.822: D/COUCOU(21238): NOTisScoreResultValid 6 GamesStatusCodes.STATUS_NETWORK_ERROR_NO_DATA
06-30 21:59:03.119: D/COUCOU(21238): NOTisScoreResultValid 7 GamesStatusCodes.STATUS_NETWORK_ERROR_NO_DATA
06-30 21:59:03.448: D/COUCOU(21238): NOTisScoreResultValid 8 GamesStatusCodes.STATUS_NETWORK_ERROR_NO_DATA
06-30 21:59:03.740: D/COUCOU(21238): NOTisScoreResultValid 9 GamesStatusCodes.STATUS_NETWORK_ERROR_NO_DATA
06-30 21:59:04.031: D/COUCOU(21238): NOTisScoreResultValid 10 GamesStatusCodes.STATUS_NETWORK_ERROR_NO_DATA
So as you can see, the first three leaderboards work well, but the 7 others dont't work. Sometime, no one of the 10 work. It's so strange.
Thanks you for help !