谷歌玩游戏
大家好.
我正在尝试在我正在开发的游戏中实现成就.
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();
}
});
}
相关文章