使用Google Play Game Services提供储蓄游戏,说明不使用“保存游戏”功能在Play Console中无法使用快照。

问题描述 投票:0回答:1
我已经在我的Android应用程序中集成了Google Play游戏服务,登录工作正常,现在我正在尝试保存游戏,但是当我尝试这样做时,我会遇到错误,说我已经在Google中启用了“保存的游戏”播放控制台,请参阅下面的屏幕截图

enter image description here

enter image description here当我要经过doc

时,我注意到它在使用保存的游戏之前也需要

java.lang.IllegalStateException: Cannot use snapshots without enabling the 'Saved Game' feature in the Play console,现在鉴于我正在使用corterential Manager,请不要将其与Google Play Play Game Services混淆通过遵循thisdoc

打开该应用程序,我已经完成了我已经进行的符号
因此,我决定将凭据管理器与Google Drive Access一起使用,这是IT的示例代码
GoogleSignInClient
一旦这成功,然后我调用以下代码来保存我的游戏

GoogleSignInClient

但是我一直看到错误说
private fun signInSilently() { val credentialManager = CredentialManager.create(this) val rawNonce = UUID.randomUUID().toString() val bytes = rawNonce.toByteArray() val md = MessageDigest.getInstance("SHA-256") val digest = md.digest(bytes) val hashedNonce = digest.fold("") { str, it -> str + "%02x".format(it) } val googleIdOption = GetGoogleIdOption.Builder() .setFilterByAuthorizedAccounts(false) //IMP Part .setServerClientId("MY_WEB_CLIENT_ID") .setAutoSelectEnabled(true) .setNonce(hashedNonce) .build() val request: GetCredentialRequest = GetCredentialRequest.Builder() .addCredentialOption(googleIdOption) .build() lifecycleScope.launch { try { val result = credentialManager.getCredential( request = request, context = this@MainActivity, ) handleSignIn(result) } catch (e: GetCredentialException) { Log.e("Erroris", "Error getting credential", e) } } } private fun handleSignIn(result: GetCredentialResponse) { // Handle the successfully returned credential. when (val credential = result.credential) { // Passkey credential is PublicKeyCredential -> { // Share responseJson such as a GetCredentialResponse on your server to // validate and authenticate val responseJson = credential.authenticationResponseJson } // Password credential is PasswordCredential -> { // Send ID and password to your server to validate and authenticate. val username = credential.id val password = credential.password } // GoogleIdToken credential is CustomCredential -> { if (credential.type == GoogleIdTokenCredential.TYPE_GOOGLE_ID_TOKEN_CREDENTIAL) { try { // Use googleIdTokenCredential and extract id to validate and // authenticate on your server. val googleIdTokenCredential = GoogleIdTokenCredential .createFrom(credential.data) val googleIdToken = googleIdTokenCredential.idToken Log.i("answer", googleIdToken) val personId = googleIdTokenCredential.id Log.i("answer", personId) //email val displayName = googleIdTokenCredential.displayName Log.i("answer", displayName.toString()) val personPhoto = googleIdTokenCredential.profilePictureUri Log.i("answer", personPhoto.toString()) val requestedScopes = listOf(Scope(DriveScopes.DRIVE_APPDATA)) val authorizationRequest = AuthorizationRequest.builder() .setRequestedScopes(requestedScopes) .build() Identity.getAuthorizationClient(this@MainActivity) .authorize(authorizationRequest) .addOnSuccessListener { if (it.hasResolution()) { val pendingIntent = it.pendingIntent val intentSenderRequest = pendingIntent?.intentSender?.let { it1 -> IntentSenderRequest.Builder( it1 ).build() } intentSenderRequest?.let { it1 -> authorizationLauncher.launch(it1) } } else { Toast.makeText( this@MainActivity, "Access already granted ", Toast.LENGTH_LONG ).show() } }.addOnFailureListener { Toast.makeText(this@MainActivity, "Failure ${it.message}", Toast.LENGTH_LONG) .show() } } catch (e: GoogleIdTokenParsingException) { Log.e("Erroris", "Received an invalid google id token response", e) } } else { // Catch any unrecognized custom credential type here. Log.e("Erroris", "Unexpected type of credential") } } else -> { // Catch any unrecognized credential type here. Log.e("Erroris", "Unexpected type of credential") } } }

,我什至等待一天,以为可能需要一些时间来传播Google服务器端的更改,但不幸的是等待不起作用

	

确保这是否解决了您的特定问题,但是我遇到了一些与我自己的代码相似的错误消息,同时尝试做与您上面描述的几乎相同的。我们的案例之间的一个具体区别是我的代码以前工作过,并且只有在我试图用凭据替换弃用的googlesignInclient时,问题才开始。

对我有用的是做以下操作:

val snapshotsClient = PlayGames.getSnapshotsClient(this) val maxNumberOfSavedGamesToShow = 5 val intentTask = snapshotsClient.getSelectSnapshotIntent( "See My Saves", true, true, maxNumberOfSavedGamesToShow ) intentTask.addOnCompleteListener { if (intentTask.isSuccessful) { savedGameLauncher.launch(intentTask.result) } else { Log.i("here123","${it.exception}") Toast.makeText(this, "Fail to get snapshot", Toast.LENGTH_LONG).show() } } private val savedGameLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> val intent = result.data if(intent != null){ val snapshotsClient = PlayGames.getSnapshotsClient(this) if (intent.hasExtra(SnapshotsClient.EXTRA_SNAPSHOT_METADATA)) { // Load a snapshot. //TODO display progress bar val snapshotMetadata = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { intent.getParcelableExtra(SnapshotsClient.EXTRA_SNAPSHOT_METADATA, SnapshotMetadata::class.java) } else { intent.getParcelableExtra(SnapshotsClient.EXTRA_SNAPSHOT_METADATA) } val mCurrentSaveName = snapshotMetadata!!.uniqueName val conflictResolutionPolicy = SnapshotsClient.RESOLUTION_POLICY_MOST_RECENTLY_MODIFIED snapshotsClient.open(mCurrentSaveName,true,conflictResolutionPolicy) .addOnFailureListener { Toast.makeText(this, "Save Game Fail", Toast.LENGTH_LONG).show() } .continueWith { val snapshot = it.result.data if(snapshot != null){ val byteArray = snapshot.snapshotContents.readFully() val stringData = String(byteArray) Log.i("datais",stringData) Toast.makeText(this, stringData, Toast.LENGTH_LONG).show() } } .addOnCompleteListener{ //TODO dismiss progress bar } } else if (intent.hasExtra(SnapshotsClient.EXTRA_SNAPSHOT_NEW)) { // Create a new snapshot named with a unique string val unique: String = BigInteger(281, Random()).toString(13) val mCurrentSaveName = "snapshotTemp-$unique" snapshotsClient.open(mCurrentSaveName,true).addOnCompleteListener{ if(it.isSuccessful){ val snapshot = it.result.data val stringData = "Level 100" if(snapshot != null){ snapshot.snapshotContents.writeBytes(stringData.toByteArray()) val metadataChange = SnapshotMetadataChange.Builder().setDescription("$stringData reached").build() snapshotsClient.commitAndClose(snapshot, metadataChange).addOnCompleteListener{ finalResult -> if(finalResult.isSuccessful){ Toast.makeText(this, "Save Game Success", Toast.LENGTH_LONG).show() } } } else { Toast.makeText(this, "Snapshot is null", Toast.LENGTH_LONG).show() } } else { Toast.makeText(this, "Save Game Fail", Toast.LENGTH_LONG).show() } } } } }
android kotlin google-play-services google-play-games
1个回答
0
投票
初始化基本上会照顾游戏符号流。保存游戏时,我进行以下操作:

java.lang.IllegalStateException: Cannot use snapshots without enabling the 'Saved Game' feature in the Play console

SavesNapShottoCloud是将数据实际保存到快照量的函数。在OnActivityResult中,我检查了请求代码:
override fun onCreate(savedInstanceState: Bundle?) {
    //...
    PlayGamesSdk.initialize(this)
}

我的初步尝试使用凭据UI,就像您上面一样,有各种各样的问题(我的理论是,即使我看上去正确,我都没有设置正确的权限。将其限制为使用授权UI +玩游戏为我工作。
希望这有帮助(如果不是您的特定情况,那么希望其他人寻求类似的解决方案)。
    

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.