「Unity/GooglePlayGames/Firebase連携」の版間の差分
提供: 初心者エンジニアの簡易メモ
(ページの作成:「===PlayGameのFirebaseユーザ認証=== <pre> Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance; Firebase.Auth.Credential credential = Firebas...」) |
|||
| 行52: | 行52: | ||
uid=AgGbeT2LIeXWUIRk0uYbeYd4uExx | uid=AgGbeT2LIeXWUIRk0uYbeYd4uExx | ||
</pre> | </pre> | ||
| + | |||
===PlayGameのログアウト=== | ===PlayGameのログアウト=== | ||
<pre> | <pre> | ||
| 行68: | 行69: | ||
==PlayGameとEmailが連携した場合== | ==PlayGameとEmailが連携した場合== | ||
firebaseのauthのユーザレコードに1行レコードがあり、PlayGameアイコンとEmailアイコンが並ぶ。 | firebaseのauthのユーザレコードに1行レコードがあり、PlayGameアイコンとEmailアイコンが並ぶ。 | ||
| + | |||
| + | |||
| + | ==PlayGame連携== | ||
| + | ===LinkWithCredentialAsyncエラー=== | ||
| + | 連携エラー | ||
| + | <pre> | ||
| + | LinkWithCredentialAsync encountered an error: System.AggregateException: One or more errors occurred. (This credential is already associated with a different user account.) ---> Firebase.Auth.FirebaseAccountLinkException: This credential is already associated with a different user account. | ||
| + | </pre> | ||
2025年8月4日 (月) 18:17時点における版
目次
PlayGameのFirebaseユーザ認証
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);
});
出力
User signed in successfully: hoge1 (pGb9NkG1Q3ZqURJQGLxvXaYXxxxx)
- firebaseのauthにユーザレコードが追加される。idはPlayGame名が追加され、ユーザーuidは、上のカッコ内の28文字ハッシュが追加される。
その他気づき
- PlayGame名に日本語名を入れてもそれが、idに入る。
- firebase登録後にPlayGameの名前を変えたときは、そのゲームにログインしてもFirebase側のidは変わらない。連携解除もされない。
PlayGameのFirebaseユーザ取得
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);
}
出力
playerName= uid=AgGbeT2LIeXWUIRk0uYbeYd4uExx
PlayGameのログアウト
((PlayGamesPlatform)Social.Active).SignOut(); Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance; auth.SignOut();
ログ出力
Debug FirebaseAuth Notifying id token listeners about a sign-out event. Debug FirebaseAuth Notifying auth state listeners about a sign-out event. Info TRuntime.CctTransportBackend Making request to: ttps://firebaselogging-pa.googleapis.com/v1/firelog/legacy/batchlog Info TRuntime.CctTransportBackend Status Code: 200
PlayGameとEmailが連携した場合
firebaseのauthのユーザレコードに1行レコードがあり、PlayGameアイコンとEmailアイコンが並ぶ。
PlayGame連携
LinkWithCredentialAsyncエラー
連携エラー
LinkWithCredentialAsync encountered an error: System.AggregateException: One or more errors occurred. (This credential is already associated with a different user account.) ---> Firebase.Auth.FirebaseAccountLinkException: This credential is already associated with a different user account.
