如何使用Google Play游戏服务从多个排行榜中加载当前用户的分数? [英] How to load scores for current user from multiple leaderboard using Google Play Games services?

查看:154
本文介绍了如何使用Google Play游戏服务从多个排行榜中加载当前用户的分数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的游戏加载时,我希望收到当前玩家在游戏的所有级别(我目前有22个)的所有分数.我正在这样做:

On load of my game I want to receive all scores for all levels (I have 22 currently) of my game for the current player. I am doing this:

@Override
public void onSignInSucceeded() {
    new Thread(new Runnable() {
        @Override
        public void run() {
            for (int i = 1; i < count; ++i)
                score = getScoreGPGS(LEVEL_LIST(i).leaderBoardID);
            // somehow use this score
        }
    }).start();
}

还有

public long getScoreGPGS(String leaderBoardID) {
    try {
        PendingResult<Leaderboards.LoadPlayerScoreResult> result;
        result = Games.Leaderboards.loadCurrentPlayerLeaderboardScore(gameHelper.getApiClient(),
                leaderBoardID, LeaderboardVariant.TIME_SPAN_ALL_TIME,
                LeaderboardVariant.COLLECTION_PUBLIC);
        LeaderboardScore score = result.await().getScore();
        if (score != null)
            return score.getRawScore();
        else
            return 0;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return -1;
}

我知道result.await().getScore();并不是最好的方法,但是其他方法也行不通(我尝试使用回调以及为所有排行榜创建PendingResults,然后在循环中等待它完整,这里不是这样,这对我来说更方便.)

I understand that result.await().getScore(); is not best way to do it, but other ways haven't worked also (I tried to use callbacks as well as to create PendingResults for all my leaderboards and then in a loop to await it to complete, it is not the case here, this one is more convenient for me).

问题是,我只能在3个第一级别(在任何互联网连接的任何设备上)上获得分数.如果我在失败的级别上执行result.await().getStatus(),则不会被成功,取消或中断,它返回的具体内容我不知道,因为我无法调试它.

The problem is that I am able to receive scores for only 3 first levels (on any device on any internet connection). if I do result.await().getStatus() on failed levels it would not be Succeded or Cancelled or Interrupted, what specifically it returns I do not know because I can't debug it.

UPD :服务器似乎阻止了我的通话.我尝试在每次调用之间将线程暂停1秒钟,但没有用,但是当我尝试将线程暂停10秒钟时,它确实起作用,但仅在6个级别上,也许增加此时间会有所帮助,但甚至10秒钟有很多时间等待.也许有不同的方法来解决这个问题?

UPD: It seems like server blocks my calls. I tried to pause thread for 1 second between each call, it didn't work, but when I tried to pause thread for 10 seconds it did work, but only for 6 levels, maybe increasing of this time will help, but even 10 second was big time to wait. Maybe there is a different approach to this issue?

UPD2 :在Google API控制台中,这些调用在API games.scores.get上显示为客户端错误",但是我很确定自己不会超过每100个用户500个查询的配额第二.

UPD2: In Google API Console these calls are shown as "client errors" on API games.scores.get, but I am pretty sure that I am not exceeding my quota of 500 queries per user per 100 second.

推荐答案

您正在受到服务器的速率限制.有关更多信息,请阅读 https://developers.google.com/games/services/quota.每100秒对每个用户的调用次数是有限制的,您可以在开发人员控制台上查看API并查看值是多少.您需要将请求限制在该限制之内.

You are experiencing rate limiting by the server. For more information read https://developers.google.com/games/services/quota. There are is a limit on the number of calls per user per 100 seconds, you can look at the API on the developer console and see what the values are. You'll need to keep your requests under that limit.

您可以申请增加限制,这是解决问题的一种方法,另一种方法可能是缓存结果并对需要进行的任何更新保持精明.

You can apply to increase the limit which is one way of solving the problem, the other approach might be to cache the results and be smart about any updates that need to be made.

或者,听起来好像您可能想要自己保存一个分数数据库,而不是使用排行榜作为数据存储.像 Firebase实时数据库之类的方法可能更合适.

Alternatively, it sounds like you might want to look at keeping a database of scores yourself, vs. using leaderboards as a datastore. Something like Firebase Realtime Database might be more appropriate.

这篇关于如何使用Google Play游戏服务从多个排行榜中加载当前用户的分数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆