Google Play游戏 [英] Google Play Games
问题描述
我试图在正在开发的游戏中实现成就。
我已经在google play console上设置了所有内容,获取了app-id,并在清单中放入以下内容:
< 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帐户= GoogleSignIn.getLastSignedInAccount(this);
PlayersClient player = Games.getPlayersClient(this,account);
当我运行它时,我得到我的帐户,但运行游戏。 getPlayersClient(this,account);
出现以下错误:
lockquote
java.lang.IllegalStateException:Games APIs需要
https://www.googleapis.com/auth/games_lite 功能。
任何人都可以想出什么可能是错误的?
。
我认为你应该检查:
GoogleSignIn.hasPermissions(帐户,Games.SCOPE_GAMES_LITE)。
如果该账户没有权限,您应该使用
GoogleSignIn.getClient(this,gso).silentSignIn或GoogleSignIn.getClient(this,gso).getSignInIntent()
加入 startActivityForResult 以接收包含 GAMES_LITE 范围的帐户。
GoogleSignIn.hasPermissions 对于空帐户也返回false,这也可能是getLastSignedInAccount的结果。
示例:
GoogleSignInAccount帐户= GoogleSignIn.getLastSignedInAccount(this);
if(GoogleSignIn.hasPermissions(account,Games.SCOPE_GAMES_LITE)){
onSignIn(account);
} else {
signInClient
.silentSignIn()
.addOnCompleteListener(
this,
task - > {
if(task。 ();
onSignIn(task.getResult());
} else {
resetSignedIn();
}
});
}
Good day everyone.
I'm trying to implement Achievements in a game I'm developing.
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" />
and wrote the following method
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);
When I run it I get my account, but as it runs Games.getPlayersClient(this, account);
I get the following error:
java.lang.IllegalStateException: Games APIs requires https://www.googleapis.com/auth/games_lite function.
Anybody as any idea what could be wrong?
Thanks in advance.
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()
with startActivityForResult to receive account with GAMES_LITE scope.
GoogleSignIn.hasPermissions also returns false for null account which could be also result of the getLastSignedInAccount.
Example:
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();
}
});
}
这篇关于Google Play游戏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!