Unable to retrive google play game services leaderboard score
Asked Answered
O

0

0

I want to get users score from leaderboard connected to google play game services. I have 6 leaderboards from which game loads only 3 leaderboards other leaderboards data I get null.

if (mGoogleApiClient.isConnected()) {
    Games.Leaderboards.loadCurrentPlayerLeaderboardScore(mGoogleApiClient,
        getString(R.string.leaderboard_best_score__normal_mode),
        LeaderboardVariant.TIME_SPAN_ALL_TIME,
        LeaderboardVariant.COLLECTION_SOCIAL).setResultCallback(
        new ResultCallback < Leaderboards.LoadPlayerScoreResult > () {
            @Override
            public void onResult(Leaderboards.LoadPlayerScoreResult arg0) {
                Log.d("myleader", "score normal : " + mGoogleApiClient.isConnected());
                if (arg0.getScore() != null) {
                    LeaderboardScore c = arg0.getScore();
                    int s = (int) c.getRawScore();
                    Log.d("myleader", "score normal : " + s);
                }
            }
        });
    Games.Leaderboards.loadCurrentPlayerLeaderboardScore(mGoogleApiClient,
        getString(R.string.leaderboard_best_time__normal_mode),
        LeaderboardVariant.TIME_SPAN_ALL_TIME,
        LeaderboardVariant.COLLECTION_SOCIAL).setResultCallback(
        new ResultCallback < Leaderboards.LoadPlayerScoreResult > () {
            @Override
            public void onResult(Leaderboards.LoadPlayerScoreResult arg0) {
                if (arg0.getScore() != null) {
                    LeaderboardScore c = arg0.getScore();
                    long s = c.getRawScore();
                    Log.d("myleader", "time normal : " + s);
                }
            }
        });
    Games.Leaderboards.loadCurrentPlayerLeaderboardScore(mGoogleApiClient,
        getString(R.string.leaderboard_best_score__reverse_mode),
        LeaderboardVariant.TIME_SPAN_ALL_TIME,
        LeaderboardVariant.COLLECTION_SOCIAL).setResultCallback(
        new ResultCallback < Leaderboards.LoadPlayerScoreResult > () {
            @Override
            public void onResult(Leaderboards.LoadPlayerScoreResult arg0) {
                if (arg0.getScore() != null) {
                    LeaderboardScore c = arg0.getScore();
                    int s = (int) c.getRawScore();
                    Log.d("myleader", "score rev : " + s);
                }
            }
        });
    Games.Leaderboards.loadCurrentPlayerLeaderboardScore(mGoogleApiClient,
        getString(R.string.leaderboard_best_time__reverse_mode),
        LeaderboardVariant.TIME_SPAN_ALL_TIME,
        LeaderboardVariant.COLLECTION_SOCIAL).setResultCallback(
        new ResultCallback < Leaderboards.LoadPlayerScoreResult > () {
            @Override
            public void onResult(Leaderboards.LoadPlayerScoreResult arg0) {
                if (arg0.getScore() != null) {
                    LeaderboardScore c = arg0.getScore();
                    long s = c.getRawScore();
                    Log.d("myleader", "time rev : " + s);
                }
            }
        });
    Games.Leaderboards.loadCurrentPlayerLeaderboardScore(mGoogleApiClient,
        getString(R.string.leaderboard_best_time__zen_mode),
        LeaderboardVariant.TIME_SPAN_ALL_TIME,
        LeaderboardVariant.COLLECTION_SOCIAL).setResultCallback(
        new ResultCallback < Leaderboards.LoadPlayerScoreResult > () {
            @Override
            public void onResult(Leaderboards.LoadPlayerScoreResult arg0) {
                if (arg0.getScore() != null) {
                    LeaderboardScore c = arg0.getScore();
                    long s = c.getRawScore();
                    Log.d("myleader", "time zen : " + s);
                }
            }
        });
    Games.Leaderboards.loadCurrentPlayerLeaderboardScore(mGoogleApiClient,
        getString(R.string.leaderboard_best_time__search_mode),
        LeaderboardVariant.TIME_SPAN_ALL_TIME,
        LeaderboardVariant.COLLECTION_SOCIAL).setResultCallback(
        new ResultCallback < Leaderboards.LoadPlayerScoreResult > () {
            @Override
            public void onResult(Leaderboards.LoadPlayerScoreResult arg0) {
                if (arg0.getScore() != null) {
                    LeaderboardScore c = arg0.getScore();
                    long s = c.getRawScore();
                    Log.d("myleader", "Time search : " + s);
                }
            }
        });

I have score in all 6 leaderboards. Here in first 3 arg0.getScore() is not null and loads leaderboard score but in last 3 leaderboards it shows arg0.getScore() is null... cursor cannot reach to Log writer in that function.

All Leaderboard ID's are correct I have checked that twice before posting Thanks in advance.

Ornis answered 4/1, 2017 at 16:30 Comment(7)
Can you check and share the value of arg0.getStatus() ? Did the result indicate any error? Was there anything in the log indicating unusual behavior?Janeenjanek
STATUS_NETWORK_ERROR_NO_DATAOrnis
If you re-order the calls do you get data for those leaderboards, or is there no data for those ids?Janeenjanek
I searched on internet and here is the problem.. Google accepts only 3 requests in 20-30 seconds .. and I'm making 6 requests here at a time.. that's why only first 3 requests gets response.. and rest get denied... What should I do now ? Should I keep it in asyncTask and keep 10 sec timer between each call ?Ornis
Oh - right the quota.. yes, the 10 sec timer between should fix it. There might be a more elegant solution that only waits if the call is denied? Do you need to load all the leaderboards each time, or can you use SaveGames API to store some information?Janeenjanek
Isn't there any way to load all the leaderboards in a single call?Ornis
With regard to waiting for a several seconds to make a request, you can make use of the Exponential Backoff. It's an algorithm that retries requests to the server based on certain status codes in the server response. The retries exponentially increase the waiting time up to a certain threshold. The idea is that if the server is down temporarily, it is not overwhelmed with requests hitting at the same time when it comes back up.Tamelatameless

© 2022 - 2024 — McMap. All rights reserved.