Google Play Games(谷歌玩游戏)
问题描述
大家好.
我正在尝试在我正在开发的游戏中实现成就.
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();
}
});
}
这篇关于谷歌玩游戏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:谷歌玩游戏
基础教程推荐
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 降序排序:Java Map 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01