谷歌玩游戏 [英] Google Play Games

查看:37
本文介绍了谷歌玩游戏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.

我正在尝试在我正在开发的游戏中实现成就.

I'm trying to implement Achievements in a game I'm developing.

我已经在 google play 控制台上设置了所有内容,获取了 app-id,将以下内容放入清单中

I already set everything on google play console, got the app-id, put in the manifest the following

    <meta-data
        android:name="com.google.android.gms.games.APP_ID"
        android:value="@string/app_id" />

并写了如下方法

        GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance();
        int temp = googleApiAvailability.isGooglePlayServicesAvailable(this);
        if ( temp != 0)
            return;

        GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN)
                .requestEmail()
                .build();

        GoogleSignIn.getClient(this, gso);

        GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);
        PlayersClient player = Games.getPlayersClient(this, account);

当我运行它时,我得到了我的帐户,但是当它运行 Games.getPlayersClient(this, account); 我得到以下错误:

When I run it I get my account, but as it runs Games.getPlayersClient(this, account); I get the following error:

java.lang.IllegalStateException:游戏 API 需要https://www.googleapis.com/auth/games_lite 函数.

java.lang.IllegalStateException: Games APIs requires https://www.googleapis.com/auth/games_lite function.

有人知道可能出了什么问题吗?

Anybody as any idea what could be wrong?

提前致谢.

推荐答案

我觉得你应该检查一下:

I think you should check:

GoogleSignIn.hasPermissions(account, Games.SCOPE_GAMES_LITE).

如果该帐户没有权限,您应该使用

And if there is no permissions in that account you should use

GoogleSignIn.getClient(this, gso).silentSignIn or GoogleSignIn.getClient(this, gso).getSignInIntent() 

使用 startActivityForResult 接收具有 GAMES_LITE 范围的帐户.

with startActivityForResult to receive account with GAMES_LITE scope.

GoogleSignIn.hasPermissions 也会为 null 帐户返回 false,这也可能是 getLastSignedInAccount 的结果.

GoogleSignIn.hasPermissions also returns false for null account which could be also result of the getLastSignedInAccount.

例子:

GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);

if (GoogleSignIn.hasPermissions(account, Games.SCOPE_GAMES_LITE)) {
    onSignIn(account);
} else {
    signInClient
      .silentSignIn()
      .addOnCompleteListener(
          this,
          task -> {
            if (task.isSuccessful()) {
              onSignIn(task.getResult());
            } else {
              resetSignedIn();
            }
          });
}

这篇关于谷歌玩游戏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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