Google Play游戏

今天是个好日子。

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

我已经在Google Play控制台上设置了所有内容,获取了应用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 account = GoogleSignIn.getLastSignedInAccount(this);

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

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

java.lang.IllegalStateException:游戏API需要

https://www.googleapis.com/auth/games_lite函数。

任何人都知道可能有什么问题吗?

提前致谢。

回答:

我认为您应该检查:

GoogleSignIn.hasPermissions(account, Games.SCOPE_GAMES_LITE).

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

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

startActivityForResult 一起接收 GAMES_LITE 范围的帐户。

__对于空帐户, GoogleSignIn.hasPermissions

还返回false,这也可能是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();

}

});

}

以上是 Google Play游戏 的全部内容, 来源链接: utcz.com/qa/428794.html

回到顶部