次の方法で共有


LoginWithWebPlayGamesServices API の移行手順

Google は開発者にこの認証方法への移行を促しているため、移行は LoginWithGamePlayGamesServices への切り替えで構成されています。 プレイヤーを移行した後、LoginWithUsbAccount API に依存することはなくなり、開発者は最新のプラグイン バージョンにアップグレードできるようになります。

詳細については、Google 公式ドキュメントを参照してください。

手順の概要

  1. 適切なバージョンの "Play Games Plugin for Unity" を選択します。
  2. Play Games Platform を初期化し、ユーザーを認証します。
  3. LoginWithFabAccount を使用して PlayFab にログインします。
  4. Google Play Games プロフィールを PlayFab Player アカウントにリンクします。
  5. ユーザーが LoginWithGamePlayGamesServices API を使用してログインできることを確認します。
  6. (省略可能) PlayFab Player アカウントから、Google アカウント プロファイルのリンクを解除します。

移行の手順

適切なバージョンの "Play Games Plugin for Unity" を選択する

最新バージョンのプラグインは移行には使用できません。これは、Google が余分なスコープの要求を認めなくなり、PlayFab の LoginWithFabAccount API が機能しなくなったためです。

ここに示した移行手順のテストと記述は、"Play Games Plugin for Unity" バージョン 0.10.14 を使用して行われています。このバージョンは playgameservices/play-games-plugin-for-unity (github.com) の v10.14 から入手できます。

プラグインのインストールと構成の手順については、プラグインの README を参照してください

Play Games プラットフォームを初期化し、プレイヤーを認証する

README の「Configuration および Initialization Play Games Services」セクションを参照し、PlayGamesClientConfiguration の一部として "profile" スコープを要求します。

 PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
     .AddOauthScope("profile")
     .RequestServerAuthCode(false)
     .Build();
 
 PlayGamesPlatform.InitializeInstance(config);
 // recommended for debugging:
 PlayGamesPlatform.DebugLogEnabled = true;
 // Activate the Google Play Games platform
 PlayGamesPlatform.Activate();
 
 // authenticate user:
 PlayGamesPlatform.Instance.Authenticate(SignInInteractivity.CanPromptOnce, (SignInStatus result) => {
     if (result == SignInStatus.Success)
     {
         Debug.Log("Authentication Succeeded.");
     }
     else
     {
         Debug.Log("Authentication Failed. SignInStatus: " + result);
     }
 });

LoginWithFabAccount を使用して PlayFab にログインする

従来の Player アカウントに、LoginWithGoogleAccount 認証 API を使用してログインします。 正常にログインするには、サーバー認証トークンを指定する必要があります。これは GetServerAuthCode メソッドで要求できます。

 public void PlayFabLoginWithGoogleAccount()
 {
     var serverAuthCode = PlayGamesPlatform.Instance.GetServerAuthCode();

     var request = new LoginWithGoogleAccountRequest
     {
         ServerAuthCode = serverAuthCode,
         TitleId = PlayFabSettings.TitleId
     };
 
     PlayFabClientAPI.LoginWithGoogleAccount(request, OnLoginWithGoogleAccountSuccess, OnLoginWithGoogleAccountFailure);
 }

 private void OnLoginWithGoogleAccountSuccess(LoginResult result)
 {
     Debug.Log("PlayFab LoginWithGoogleAccount Success.");
 }

 private void OnLoginWithGoogleAccountFailure(PlayFabError error)
 {
     Debug.Log("PlayFab LoginWithGoogleAccount Failure: " + error.GenerateErrorReport());
 }

移行以前の段階で、Google アカウントにリンクされているユーザーは、ゲーム マネージャーには次のように表示されています。

LoginWithGamePlayGamesServices への移行手順 1

この手順では、プレイヤーの Google Play Games アカウントを、Google アカウントにのみリンクされていた既存プレイヤーの PlayFab アカウントにリンクします。

public void LinkGooglePlayGamesAccount()
{
    PlayGamesPlatform.Instance.GetAnotherServerAuthCode(true, (serverAuthCode) => {

        var linkRequest = new LinkGooglePlayGamesServicesAccountRequest
        {
            ServerAuthCode = serverAuthCode
        };

        PlayFabClientAPI.LinkGooglePlayGamesServicesAccount(linkRequest, OnLinkGooglePlayGamesServicesAccountSuccess, OnLinkGooglePlayGamesServicesAccountFailure);
    });
}

private void OnLinkGooglePlayGamesServicesAccountSuccess(LinkGooglePlayGamesServicesAccountResult result)
{
    Debug.Log("PlayFab LinkGooglePlayGamesServicesAccount Success");
}

private void OnLinkGooglePlayGamesServicesAccountFailure(PlayFabError error)
{
    Debug.Log("PlayFab LinkGooglePlayGamesServicesAccount Failure: " + error.GenerateErrorReport());
}

この手順が正常に完了すると、当該プレイヤーは、PlayFab 側に両方のアカウント プロファイルが関連付けられ、以後 LoginWithGamePlayGamesServices 認証 API を使用できるようになります。

ゲーム マネージャーを開くと、次のように、プレイヤーに関連付けられている両方のアカウントが表示されます。

LoginWithGamePlayGamesServices への移行手順 2

LoginWithGamePlayGamesServices API でプレイヤーのログインが可能であることを確認する


 public void PFLoginWithGooglePlayGames()
 {
     PlayGamesPlatform.Instance.GetAnotherServerAuthCode(true, (serverAuthCode) => {

         var request = new LoginWithGooglePlayGamesServicesRequest
         {
             ServerAuthCode = serverAuthCode,
             CreateAccount = false,
             TitleId = PlayFabSettings.TitleId
         };
 
         PlayFabClientAPI.LoginWithGooglePlayGamesServices(request, OnLoginWithGooglePlayGamesServicesSuccess, OnLoginWithGooglePlayGamesServicesFailure);
     });
 }

 private void OnLoginWithGooglePlayGamesServicesSuccess(LoginResult result)
 {
     Debug.Log("PlayFab LoginWithGooglePlayGamesServices Success.");
 }

 private void OnLoginWithGooglePlayGamesServicesFailure(PlayFabError error)
 {
     Debug.Log("PlayFab LoginWithGooglePlayGamesServices Failure: " + error.GenerateErrorReport());
 }

この手順は省略可能です。 しかし、Google Play Games Services プロファイルがプレイヤー アカウントにリンクされたこと、PlayFab に正常にログインできることを確認した後は、プレイヤーのプロフィールにリンクされている従来の Google アカウント プロファイルを UnlinkWebAccount API でリンク解除し、loginWithGamePlayGamesServices API のみによる使用方法へと移行することをお勧めします。

 public void UnlinkGoogleAccountFromPlayer()
 {
     PlayFabClientAPI.UnlinkGoogleAccount(new UnlinkGoogleAccountRequest(), OnUnlinkGoogleAccountSuccess, OnUnlinkGoogleAccountFailure);
 }
 
 private void OnUnlinkGoogleAccountSuccess(UnlinkGoogleAccountResult result)
 {
     Debug.Log("PlayFab UnlinkGoogleAccount Success.");
 }
 
 private void OnUnlinkGoogleAccountFailure(PlayFabError error)
 {
     Debug.Log("PlayFab UnlinkGoogleAccount Failure: " + error.GenerateErrorReport());
 }

リンクを解除すると、次のように、プレイヤーのゲーム マネージャーには Google Play ゲーム ID のみが表示されるようになります。

LoginWithGamePlayGamesServices への移行手順 3