「Unity/GooglePlayGames/ver2」の版間の差分
(→unityのGamePlayの初期設定確認) |
(→PlayGame認証で、"Returning an error code"が起こるとき) |
||
| (同じ利用者による、間の22版が非表示) | |||
| 行1: | 行1: | ||
| + | ==確認したバージョン== | ||
| + | *Firebase:12.10.1 | ||
| + | *PlayGame:v.2.1.0 | ||
| + | |||
| + | ==v2の公式マニュアル== | ||
| + | Unity 用 Google Play Games を設定してログインする https://developer.android.com/games/pgs/unity/unity-start?hl=ja | ||
| + | |||
| + | Play Games サービス v2 に移行する(Unity) https://developer.android.com/games/pgs/unity/migrate-to-v2?hl=ja | ||
| + | |||
==Androidビルドで"mergeDexRelease"エラーが出る== | ==Androidビルドで"mergeDexRelease"エラーが出る== | ||
エラー詳細 | エラー詳細 | ||
| 行6: | 行15: | ||
> Failed to transform classes.jar (project :unityLibrary) to match attributes {artifactType=android-dex, asm-transformed-variant=NONE, com.android.build.api.attributes.AgpVersionAttr=7.1.2, com.android.build.api.attributes.BuildTypeAttr=release, com.android.build.gradle.internal.attributes.VariantAttr=release, dexing-enable-desugaring=true, dexing-is-debuggable=false, dexing-min-sdk=23, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}. | > Failed to transform classes.jar (project :unityLibrary) to match attributes {artifactType=android-dex, asm-transformed-variant=NONE, com.android.build.api.attributes.AgpVersionAttr=7.1.2, com.android.build.api.attributes.BuildTypeAttr=release, com.android.build.gradle.internal.attributes.VariantAttr=release, dexing-enable-desugaring=true, dexing-is-debuggable=false, dexing-min-sdk=23, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}. | ||
> Could not resolve all files for configuration ':launcher:releaseRuntimeClasspath'. | > Could not resolve all files for configuration ':launcher:releaseRuntimeClasspath'. | ||
| − | > No variants of com.google.games:gpgs-plugin-support:2. | + | > No variants of com.google.games:gpgs-plugin-support:2.1.0 match the consumer attributes: |
| − | - com.google.games:gpgs-plugin-support:2. | + | - com.google.games:gpgs-plugin-support:2.1.0 configuration runtime: |
- Incompatible because this component declares attribute 'artifactType' with value 'srcaar' and the consumer needed attribute 'artifactType' with value 'android-classes-jar' | - Incompatible because this component declares attribute 'artifactType' with value 'srcaar' and the consumer needed attribute 'artifactType' with value 'android-classes-jar' | ||
- Other compatible attributes: | - Other compatible attributes: | ||
| 行23: | 行32: | ||
</pre> | </pre> | ||
対策 | 対策 | ||
| − | #Assets/GooglePlayGames/com.google.play.games/Editor/m2repository/com/google/games/gpgs-plugin-support/2. | + | #Assets/GooglePlayGames/com.google.play.games/Editor/m2repository/com/google/games/gpgs-plugin-support/2.1.0にある srcaar 拡張子を aar へ |
| − | #Assets/GooglePlayGames/com.google.play.games/Editor/m2repository/com/google/games/gpgs-plugin-support/2. | + | #Assets/GooglePlayGames/com.google.play.games/Editor/m2repository/com/google/games/gpgs-plugin-support/2.1.0/gpgs-plugin-support-2.1.0.pom の srcaar を aar へ。 |
<pre> | <pre> | ||
<?xml version="1.0" encoding="UTF-8"?> | <?xml version="1.0" encoding="UTF-8"?> | ||
| 行31: | 行40: | ||
<groupId>com.google.games</groupId> | <groupId>com.google.games</groupId> | ||
<artifactId>gpgs-plugin-support</artifactId> | <artifactId>gpgs-plugin-support</artifactId> | ||
| − | <version>2. | + | <version>2.1.0</version> |
- <packaging>srcaar</packaging> | - <packaging>srcaar</packaging> | ||
+ <packaging>aar</packaging> | + <packaging>aar</packaging> | ||
| 行56: | 行65: | ||
公式:https://firebase.google.com/docs/auth/unity/play-games?hl=ja | 公式:https://firebase.google.com/docs/auth/unity/play-games?hl=ja | ||
#unityのplatformをAndroidにする。 | #unityのplatformをAndroidにする。 | ||
| − | #unityメインメニューから[Window] > [Google Play Games] > [Setup] > [Android Setup] | + | #unityメインメニューから[Window] > [Google Play Games] > [Setup] > [Android Setup] を開き以下を入れる。 |
| − | + | <pre> | |
| − | + | Directory to save Constant:Assets/GooglePlayGames | |
| + | Constant class name:GPGSIds | ||
| + | |||
| + | Paste in the AndroidResources from the Play Console | ||
| + | <?xml version="1.0" encoding="utf-8"?> | ||
| + | <!-- | ||
| + | Google Play game services IDs. | ||
| + | Save this file as res/values/games-ids.xml in your project. | ||
| + | --> | ||
| + | <resources> | ||
| + | <!-- app_id --> | ||
| + | <string name="app_id" translatable="false">[ここにAPP_IDを入れる]</string> | ||
| + | <!-- package_name --> | ||
| + | <string name="package_name" translatable="false">com.example.project1</string> | ||
| + | <!-- event Wiped Raid --> | ||
| + | <string name="event_wiped_raid" translatable="false">[ここにevent_wiped_raidをいれる]</string> | ||
| + | </resources> | ||
| + | |||
| + | WebAppClientId:gcp&play画面で入れた、ウェブアプリケーションのClientId | ||
| + | </pre> | ||
ProjectSettings/GooglePlayGameSettings.txt に APP_IDが入ることを確認。 | ProjectSettings/GooglePlayGameSettings.txt に APP_IDが入ることを確認。 | ||
| + | |||
| + | ProjectSettings/GooglePlayGameSettings.txt | ||
| + | proj.AppId=12345678901 | ||
| + | and.ClientId=12345678901-abcdef1234567890abcdef1234567890ab.apps.googleusercontent.com | ||
====unityのGamePlayの初期設定確認==== | ====unityのGamePlayの初期設定確認==== | ||
| 行79: | 行111: | ||
<meta-data android:name="com.google.android.gms.games.unityVersion" | <meta-data android:name="com.google.android.gms.games.unityVersion" | ||
| − | android:value="\u0032. | + | android:value="\u0032.1.0" /> |
</pre> | </pre> | ||
| − | |||
| − | |||
| − | |||
====[Window] > [Google Play Games] > [Setup]でAndroidSetupが選択できないとき==== | ====[Window] > [Google Play Games] > [Setup]でAndroidSetupが選択できないとき==== | ||
#unityのplatformをAndroidにする。 | #unityのplatformをAndroidにする。 | ||
| − | ==== | + | ===="Error SignInRequest Sign-in failed with status code: 10"エラーが発生するとき==== |
| + | PlayConsoleのアップロード鍵の証明書が表示されてるか確認する。 | ||
| + | |||
| + | apkを上げてなければ、署名付きのapkをupして、アップロード鍵の証明書が表示されるか確認する | ||
| + | |||
| + | ====PlayGame認証で、DEVELOPER_ERRORが起こるとき==== | ||
| + | エラー詳細 | ||
<pre> | <pre> | ||
| − | + | **** APP NOT CORRECTLY CONFIGURED TO USE GOOGLE PLAY GAME SERVICES | |
| − | + | **** DEVELOPER_ERROR | |
| + | **** This is usually caused by one of these reasons: | ||
| + | **** (1) Your package name and certificate fingerprint do not match | ||
| + | **** the client ID you registered in Developer Console. | ||
| + | **** (2) Your App ID was incorrectly entered. | ||
| + | **** (3) Your game settings have not been published and you are | ||
| + | **** trying to log in with an account that is not listed as | ||
| + | **** a test account. | ||
| + | **** (4) A server auth code was requested, but an incorrect client | ||
| + | **** id was provided. The client id for server auth codes should | ||
| + | **** be the client id for the game server (not the android app). | ||
| + | **** | ||
| + | **** To help you debug, here is the information about this app | ||
| + | **** Package name : com.example.project1 | ||
| + | **** Cert SHA1 fingerprint: D7:D7:D7:D7:D7:D7:D7:D7:D7:D7:D7:D7:D7:D7:D7:D7:D7:D7:D7:D7 | ||
| + | **** App ID from manifest : 12345678901 | ||
| + | **** | ||
| + | **** Check that the above information matches your setup in | ||
| + | **** Developer Console. Also, check that you're logging in with the | ||
| + | **** right account (it should be listed in the Testers section if | ||
| + | **** your project is not yet published). | ||
| + | **** | ||
| + | **** For more information, refer to the troubleshooting guide: | ||
| + | **** http://developers.google.com/games/services/android/troubleshooting | ||
| + | **** | ||
</pre> | </pre> | ||
| − | + | GCPに登録した、ウェブアプリケーションIDと、アプリに登録したものが、同じかどうか確認する。 | |
| − | ==== | + | ====PlayGame認証で、"Returning an error code"が起こるとき==== |
| − | + | releaseバージョンで認証させたときに、以下エラーコードが起こる場合 | |
<pre> | <pre> | ||
| − | + | *** [Play Games Plugin 2.1.0] ERROR: Returning an error code. | |
| − | + | ||
</pre> | </pre> | ||
| − | + | GCPに登録した、ウェブアプリケーションIDと、アプリに登録したものが、同じかどうか確認する。 | |
| − | + | releaseバージョンで認証させたときに、上記エラーコードが起こる。debugバージョンだと、多分、DEVELOPER_ERRORのエラーが起こる。 | |
| − | + | ||
| − | + | 参考:https://discussions.unity.com/t/google-play-games-canceled/938672/10 | |
| + | |||
| + | |||
| + | 確認Android端末内のPlayGameアプリで、連携してるアカウントが、ログアウトされてる可能性があるので、実機のPlayGameアプリを、確認する。 | ||
| + | |||
| + | ===Google ログインのScope項目=== | ||
| + | 参考:https://developers.google.com/identity/protocols/oauth2/scopes?hl=ja | ||
| + | <pre> | ||
| + | 範囲 説明 | ||
| + | email Google アカウントのメインのメールアドレスを表示する | ||
| + | openid Google で公開されているお客様の個人情報とお客様を関連付ける | ||
| + | profile ユーザーの個人情報の表示(ユーザーが一般公開しているすべての個人情報を含む) | ||
| + | </pre> | ||
| + | |||
| + | ==サンプル実行== | ||
| + | <pre> | ||
| + | using UnityEngine; | ||
| + | using UnityEngine.UI; | ||
| + | |||
| + | #if UNITY_ANDROID | ||
| + | using GooglePlayGames; | ||
| + | using GooglePlayGames.BasicApi; | ||
| + | using System.Collections.Generic; | ||
| + | |||
| + | public class GooglePlayGameScene : MonoBehaviour | ||
| + | { | ||
| + | [SerializeField] InputField text; | ||
| + | [SerializeField] Button loginButton; | ||
| + | [SerializeField] Button logoutButton; | ||
| + | |||
| + | // Define selectedScope having additional identity scopes. | ||
| + | private List<AuthScope> selectedScopes = new List<AuthScope>(); | ||
| + | |||
| + | void Start() | ||
| + | { | ||
| + | #if UNITY_EDITOR | ||
| + | Debug.LogError("Android実機端末以外では動作しません"); | ||
| + | #endif | ||
| + | Debug.Log("GooglePlayGameScene start"); | ||
| + | text.text = "GooglePlayGameScene start\n"; | ||
| + | Debug.Log("GooglePlayGameScene end"); | ||
| + | text.text += "GooglePlayGameScene end\n"; | ||
| + | |||
| + | loginButton.onClick.AddListener(LoginOnClick); | ||
| + | logoutButton.onClick.AddListener(LogoutOnClick); | ||
| + | } | ||
| + | internal void ProcessAuthentication(SignInStatus status) | ||
| + | { | ||
| + | if (status == SignInStatus.Success) | ||
| + | { | ||
| + | Debug.Log("GooglePlayGameScene ProcessAuthentication: SignInStatus.Success"); | ||
| + | // Continue with Play Games Services | ||
| + | // Add scopes you want to request. | ||
| + | // selectedScopes.Add(AuthScope.OPEN_ID); | ||
| + | // selectedScopes.Add(AuthScope.PROFILE); | ||
| + | selectedScopes.Add(AuthScope.EMAIL); | ||
| + | |||
| + | // Call RequestServerSideAccess with additional scopes and retrieve | ||
| + | // authcode and grantedscopes list. | ||
| + | PlayGamesPlatform.Instance.RequestServerSideAccess( | ||
| + | /* forceRefreshToken= */ false, selectedScopes, | ||
| + | (AuthResponse authResponse) => | ||
| + | { | ||
| + | Debug.Log("Received authResponse: " + authResponse); | ||
| + | string authCode = authResponse.GetAuthCode(); | ||
| + | Debug.Log("authCode=" + authCode); | ||
| + | List<AuthScope> grantedScopes = authResponse.GetGrantedScopes(); | ||
| + | foreach (var grantedScope in grantedScopes) | ||
| + | { | ||
| + | Debug.Log("grantedScope=" + grantedScope); | ||
| + | } | ||
| + | GooglePlaySuccess(authCode); | ||
| + | }); | ||
| + | } | ||
| + | else | ||
| + | { | ||
| + | // Disable your integration with Play Games Services or show a login | ||
| + | // button to ask users to sign-in. Clicking it should call | ||
| + | PlayGamesPlatform.Instance.ManuallyAuthenticate(ProcessAuthentication); | ||
| + | } | ||
| + | } | ||
| + | void LoginOnClick() | ||
| + | { | ||
| + | Debug.Log("GooglePlayGameScene LoginOnClick"); | ||
| + | PlayGamesPlatform.Instance.Authenticate(ProcessAuthentication); | ||
| + | } | ||
| + | void GooglePlaySuccess(string authCode) | ||
| + | { | ||
| + | Debug.Log("GooglePlayGameScene GooglePlaySuccess"); | ||
| + | Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance; | ||
| + | Firebase.Auth.Credential credential = Firebase.Auth.PlayGamesAuthProvider.GetCredential(authCode); | ||
| + | auth.SignInAndRetrieveDataWithCredentialAsync(credential).ContinueWith(task => | ||
| + | { | ||
| + | if (task.IsCanceled) | ||
| + | { | ||
| + | Debug.LogError("SignInAndRetrieveDataWithCredentialAsync was canceled."); | ||
| + | return; | ||
| + | } | ||
| + | if (task.IsFaulted) | ||
| + | { | ||
| + | Debug.LogError("SignInAndRetrieveDataWithCredentialAsync encountered an error: " + task.Exception); | ||
| + | return; | ||
| + | } | ||
| + | |||
| + | Firebase.Auth.AuthResult result = task.Result; | ||
| + | Debug.LogFormat("User signed in successfully: {0} ({1})", | ||
| + | result.User.DisplayName, result.User.UserId); | ||
| + | |||
| + | // ユーザ取得 | ||
| + | Firebase.Auth.FirebaseUser user = auth.CurrentUser; | ||
| + | if (user != null && user.IsValid()) | ||
| + | { | ||
| + | string playerName = user.DisplayName; | ||
| + | |||
| + | // The user's Id, unique to the Firebase project. | ||
| + | // Do NOT use this value to authenticate with your backend server, if you | ||
| + | // have one; use User.TokenAsync() instead. | ||
| + | string uid = user.UserId; | ||
| + | Debug.Log("playerName=" + playerName); | ||
| + | Debug.Log("uid=" + uid); | ||
| + | // UI更新(メインスレッドじゃないのでコメントアウト) | ||
| + | // text.text += "playerName=" + playerName + "\n"; | ||
| + | // text.text += "uid=" + uid + "\n"; | ||
| + | } | ||
| + | else | ||
| + | { | ||
| + | Debug.LogError("FirebaseUser is null or not valid."); | ||
| + | } | ||
| + | }); | ||
| + | } | ||
| + | void LogoutOnClick() | ||
| + | { | ||
| + | Debug.Log("GooglePlayGameScene LogoutOnClick"); | ||
| + | Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance; | ||
| + | auth.SignOut(); | ||
| + | } | ||
| + | } | ||
| + | #endif | ||
| + | </pre> | ||
| + | 出力 | ||
| + | <pre> | ||
| + | GooglePlayGameScene ProcessAuthentication: SignInStatus.Success | ||
| + | Received authResponse: AuthResponse { grantedScopes = EMAIL, authCode = 4/0AVMBsJhSzcTORSqYtrD1MFxbKghrqDhh3wkxtmvuxUAlo5hctS0mA1234123412341234-2 } | ||
| + | authCode=0AVMBsJhSzcTORSqYtrD1MFxbKghrqDhh3wkxtmvuxUAlo5hctS0mA1234123412341234-w | ||
| + | grantedScope=EMAIL | ||
| + | GooglePlayGameScene GooglePlaySuccess | ||
| + | User signed in successfully: hogeuser (abcedfghijklmnABCDEFG12341234) | ||
| + | playerName=hogeuser | ||
| + | uid=abcedfghijklmnABCDEFG12341234 | ||
| + | </pre> | ||
2025年8月28日 (木) 20:19時点における最新版
目次
確認したバージョン
- Firebase:12.10.1
- PlayGame:v.2.1.0
v2の公式マニュアル
Unity 用 Google Play Games を設定してログインする https://developer.android.com/games/pgs/unity/unity-start?hl=ja
Play Games サービス v2 に移行する(Unity) https://developer.android.com/games/pgs/unity/migrate-to-v2?hl=ja
Androidビルドで"mergeDexRelease"エラーが出る
エラー詳細
Execution failed for task ':launcher:mergeDexRelease'.
> Could not resolve all files for configuration ':launcher:releaseRuntimeClasspath'.
> Failed to transform classes.jar (project :unityLibrary) to match attributes {artifactType=android-dex, asm-transformed-variant=NONE, com.android.build.api.attributes.AgpVersionAttr=7.1.2, com.android.build.api.attributes.BuildTypeAttr=release, com.android.build.gradle.internal.attributes.VariantAttr=release, dexing-enable-desugaring=true, dexing-is-debuggable=false, dexing-min-sdk=23, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
> Could not resolve all files for configuration ':launcher:releaseRuntimeClasspath'.
> No variants of com.google.games:gpgs-plugin-support:2.1.0 match the consumer attributes:
- com.google.games:gpgs-plugin-support:2.1.0 configuration runtime:
- Incompatible because this component declares attribute 'artifactType' with value 'srcaar' and the consumer needed attribute 'artifactType' with value 'android-classes-jar'
- Other compatible attributes:
- Doesn't say anything about asm-transformed-variant (required 'NONE')
- Doesn't say anything about dexing-enable-desugaring (required 'true')
- Doesn't say anything about dexing-is-debuggable (required 'false')
- Doesn't say anything about dexing-min-sdk (required '24')
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 4m 3s
対策
- Assets/GooglePlayGames/com.google.play.games/Editor/m2repository/com/google/games/gpgs-plugin-support/2.1.0にある srcaar 拡張子を aar へ
- Assets/GooglePlayGames/com.google.play.games/Editor/m2repository/com/google/games/gpgs-plugin-support/2.1.0/gpgs-plugin-support-2.1.0.pom の srcaar を aar へ。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.google.games</groupId>
<artifactId>gpgs-plugin-support</artifactId>
<version>2.1.0</version>
- <packaging>srcaar</packaging>
+ <packaging>aar</packaging>
<dependencies>
<dependency>
<groupId>com.google.android.gms</groupId>
<artifactId>play-services-games-v2</artifactId>
<version>20.1.2</version>
</dependency>
<dependency>
<groupId>com.google.android.gms</groupId>
<artifactId>play-services-nearby</artifactId>
<version>18.5.0</version>
</dependency>
</dependencies>
</project>
参考:https://www.reddit.com/r/Unity3D/comments/1h4szl0/unity_android_update_sdks_to_use_api_34_and_lots/
設定
Google Play GamesのAndroid Setupの設定
公式:https://firebase.google.com/docs/auth/unity/play-games?hl=ja
- unityのplatformをAndroidにする。
- unityメインメニューから[Window] > [Google Play Games] > [Setup] > [Android Setup] を開き以下を入れる。
Directory to save Constant:Assets/GooglePlayGames Constant class name:GPGSIds Paste in the AndroidResources from the Play Console <?xml version="1.0" encoding="utf-8"?> <!-- Google Play game services IDs. Save this file as res/values/games-ids.xml in your project. --> <resources> <!-- app_id --> <string name="app_id" translatable="false">[ここにAPP_IDを入れる]</string> <!-- package_name --> <string name="package_name" translatable="false">com.example.project1</string> <!-- event Wiped Raid --> <string name="event_wiped_raid" translatable="false">[ここにevent_wiped_raidをいれる]</string> </resources> WebAppClientId:gcp&play画面で入れた、ウェブアプリケーションのClientId
ProjectSettings/GooglePlayGameSettings.txt に APP_IDが入ることを確認。
ProjectSettings/GooglePlayGameSettings.txt
proj.AppId=12345678901 and.ClientId=12345678901-abcdef1234567890abcdef1234567890ab.apps.googleusercontent.com
unityのGamePlayの初期設定確認
Assets/GooglePlayGames/com.google.play.games/Runtime/Scripts/GameInfo.cs
public const string ApplicationId = "12345678901"; // Filled in automatically public const string IosClientId = "__IOS_CLIENTID__"; // Filled in automatically public const string WebClientId = "12345678901-abcdef1234567890abcdef1234567890ab.apps.googleusercontent.com"; // Filled in automatically public const string NearbyConnectionServiceId = "";
上のClientIdなどが入ってることを確認
Assets/Plugins/Android/GooglePlayGamesManifest.androidlib/AndroidManifest.xml にAPP_IDが入ってること。\u003はユニコード用のもので、入っていても問題ない。
<meta-data android:name="com.google.android.gms.games.APP_ID"
android:value="\u00312345678901" />
<meta-data android:name="com.google.android.gms.games.unityVersion"
android:value="\u0032.1.0" />
[Window] > [Google Play Games] > [Setup]でAndroidSetupが選択できないとき
- unityのplatformをAndroidにする。
"Error SignInRequest Sign-in failed with status code: 10"エラーが発生するとき
PlayConsoleのアップロード鍵の証明書が表示されてるか確認する。
apkを上げてなければ、署名付きのapkをupして、アップロード鍵の証明書が表示されるか確認する
PlayGame認証で、DEVELOPER_ERRORが起こるとき
エラー詳細
**** APP NOT CORRECTLY CONFIGURED TO USE GOOGLE PLAY GAME SERVICES **** DEVELOPER_ERROR **** This is usually caused by one of these reasons: **** (1) Your package name and certificate fingerprint do not match **** the client ID you registered in Developer Console. **** (2) Your App ID was incorrectly entered. **** (3) Your game settings have not been published and you are **** trying to log in with an account that is not listed as **** a test account. **** (4) A server auth code was requested, but an incorrect client **** id was provided. The client id for server auth codes should **** be the client id for the game server (not the android app). **** **** To help you debug, here is the information about this app **** Package name : com.example.project1 **** Cert SHA1 fingerprint: D7:D7:D7:D7:D7:D7:D7:D7:D7:D7:D7:D7:D7:D7:D7:D7:D7:D7:D7:D7 **** App ID from manifest : 12345678901 **** **** Check that the above information matches your setup in **** Developer Console. Also, check that you're logging in with the **** right account (it should be listed in the Testers section if **** your project is not yet published). **** **** For more information, refer to the troubleshooting guide: **** http://developers.google.com/games/services/android/troubleshooting ****
GCPに登録した、ウェブアプリケーションIDと、アプリに登録したものが、同じかどうか確認する。
PlayGame認証で、"Returning an error code"が起こるとき
releaseバージョンで認証させたときに、以下エラーコードが起こる場合
*** [Play Games Plugin 2.1.0] ERROR: Returning an error code.
GCPに登録した、ウェブアプリケーションIDと、アプリに登録したものが、同じかどうか確認する。
releaseバージョンで認証させたときに、上記エラーコードが起こる。debugバージョンだと、多分、DEVELOPER_ERRORのエラーが起こる。
参考:https://discussions.unity.com/t/google-play-games-canceled/938672/10
確認Android端末内のPlayGameアプリで、連携してるアカウントが、ログアウトされてる可能性があるので、実機のPlayGameアプリを、確認する。
Google ログインのScope項目
参考:https://developers.google.com/identity/protocols/oauth2/scopes?hl=ja
範囲 説明 email Google アカウントのメインのメールアドレスを表示する openid Google で公開されているお客様の個人情報とお客様を関連付ける profile ユーザーの個人情報の表示(ユーザーが一般公開しているすべての個人情報を含む)
サンプル実行
using UnityEngine;
using UnityEngine.UI;
#if UNITY_ANDROID
using GooglePlayGames;
using GooglePlayGames.BasicApi;
using System.Collections.Generic;
public class GooglePlayGameScene : MonoBehaviour
{
[SerializeField] InputField text;
[SerializeField] Button loginButton;
[SerializeField] Button logoutButton;
// Define selectedScope having additional identity scopes.
private List<AuthScope> selectedScopes = new List<AuthScope>();
void Start()
{
#if UNITY_EDITOR
Debug.LogError("Android実機端末以外では動作しません");
#endif
Debug.Log("GooglePlayGameScene start");
text.text = "GooglePlayGameScene start\n";
Debug.Log("GooglePlayGameScene end");
text.text += "GooglePlayGameScene end\n";
loginButton.onClick.AddListener(LoginOnClick);
logoutButton.onClick.AddListener(LogoutOnClick);
}
internal void ProcessAuthentication(SignInStatus status)
{
if (status == SignInStatus.Success)
{
Debug.Log("GooglePlayGameScene ProcessAuthentication: SignInStatus.Success");
// Continue with Play Games Services
// Add scopes you want to request.
// selectedScopes.Add(AuthScope.OPEN_ID);
// selectedScopes.Add(AuthScope.PROFILE);
selectedScopes.Add(AuthScope.EMAIL);
// Call RequestServerSideAccess with additional scopes and retrieve
// authcode and grantedscopes list.
PlayGamesPlatform.Instance.RequestServerSideAccess(
/* forceRefreshToken= */ false, selectedScopes,
(AuthResponse authResponse) =>
{
Debug.Log("Received authResponse: " + authResponse);
string authCode = authResponse.GetAuthCode();
Debug.Log("authCode=" + authCode);
List<AuthScope> grantedScopes = authResponse.GetGrantedScopes();
foreach (var grantedScope in grantedScopes)
{
Debug.Log("grantedScope=" + grantedScope);
}
GooglePlaySuccess(authCode);
});
}
else
{
// Disable your integration with Play Games Services or show a login
// button to ask users to sign-in. Clicking it should call
PlayGamesPlatform.Instance.ManuallyAuthenticate(ProcessAuthentication);
}
}
void LoginOnClick()
{
Debug.Log("GooglePlayGameScene LoginOnClick");
PlayGamesPlatform.Instance.Authenticate(ProcessAuthentication);
}
void GooglePlaySuccess(string authCode)
{
Debug.Log("GooglePlayGameScene GooglePlaySuccess");
Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
Firebase.Auth.Credential credential = Firebase.Auth.PlayGamesAuthProvider.GetCredential(authCode);
auth.SignInAndRetrieveDataWithCredentialAsync(credential).ContinueWith(task =>
{
if (task.IsCanceled)
{
Debug.LogError("SignInAndRetrieveDataWithCredentialAsync was canceled.");
return;
}
if (task.IsFaulted)
{
Debug.LogError("SignInAndRetrieveDataWithCredentialAsync encountered an error: " + task.Exception);
return;
}
Firebase.Auth.AuthResult result = task.Result;
Debug.LogFormat("User signed in successfully: {0} ({1})",
result.User.DisplayName, result.User.UserId);
// ユーザ取得
Firebase.Auth.FirebaseUser user = auth.CurrentUser;
if (user != null && user.IsValid())
{
string playerName = user.DisplayName;
// The user's Id, unique to the Firebase project.
// Do NOT use this value to authenticate with your backend server, if you
// have one; use User.TokenAsync() instead.
string uid = user.UserId;
Debug.Log("playerName=" + playerName);
Debug.Log("uid=" + uid);
// UI更新(メインスレッドじゃないのでコメントアウト)
// text.text += "playerName=" + playerName + "\n";
// text.text += "uid=" + uid + "\n";
}
else
{
Debug.LogError("FirebaseUser is null or not valid.");
}
});
}
void LogoutOnClick()
{
Debug.Log("GooglePlayGameScene LogoutOnClick");
Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
auth.SignOut();
}
}
#endif
出力
GooglePlayGameScene ProcessAuthentication: SignInStatus.Success
Received authResponse: AuthResponse { grantedScopes = EMAIL, authCode = 4/0AVMBsJhSzcTORSqYtrD1MFxbKghrqDhh3wkxtmvuxUAlo5hctS0mA1234123412341234-2 }
authCode=0AVMBsJhSzcTORSqYtrD1MFxbKghrqDhh3wkxtmvuxUAlo5hctS0mA1234123412341234-w
grantedScope=EMAIL
GooglePlayGameScene GooglePlaySuccess
User signed in successfully: hogeuser (abcedfghijklmnABCDEFG12341234)
playerName=hogeuser
uid=abcedfghijklmnABCDEFG12341234
