Play Games Services Recall をアプリに統合する

独自のアカウント システムを引き続き使用しながら、ユーザーをゲームにシームレスにログインさせます。Play Games Services Recall API を使用すると、ゲーム内アカウントを Google Play Games サービス アカウントにリンクできます。これにより、ユーザーが異なるデバイス(またはゲームを再インストールした後の同じデバイス)でゲームをプレイするときに、リンクされたゲーム内アカウントをクエリし、ログインフローを効率化できます。

Android Recall API を統合している場合は、これらの Recall API は使い慣れているはずです。Android と PC の両方で同じであるため、Play Games サービス リコールとのサーバーサイド統合は、PC タイトルで再利用できます。

前提条件

ステップ 1: マニフェストに Play Games 開発者サービスのプロジェクト ID を追加する

Google Play Console で Play ゲームサービスの設定を完了すると、ゲームに Play ゲームサービスのプロジェクト ID が関連付けられます。このプロジェクト ID(Google Play Console の Play Games サービスの [設定] ページで確認できます)を使用して、ゲームの manifest.xml を更新します。

manifest.xml コンテンツの例:

<?xml version="1.0" encoding="utf-8"?>
<Manifest version="1">
    <Application>
        <PackageName>com.example.package</PackageName>
        <PlayGamesServices>
            <ProjectId>123456789</ProjectId>
        </PlayGamesServices>
    </Application>
</Manifest>

ステップ 2: ログイン時にリコール アクセスをリクエストする

ゲーム内でアカウントを追加するなど、ゲームがログインフローを処理している場合は、GamesRecallClient::RequestRecallAccess() を使用してリコール アクセスをリクエストします。

この呼び出しは、バックエンドで Google に対してサーバーサイド呼び出しを行い、ゲーム内アカウントと Play Games サービス ユーザーのリンクとリンク解除を行うために使用されるセッション ID を返します。

auto promise = std::make_shared<std::promise<RecallAccessResult>>();
games_recall_client.RequestRecallAccess(params, [promise](RecallAccessResult result) {
   promise->set_value(std::move(result));
});

auto recall_access_result = promise->get_future().get();
if (recall_access_result.ok()) {
   auto recall_session_id = recall_access_result.value().recall_session_id;
   // Pass the recall session ID to your backend game server so it can query
   // for an existing linked in-game account.
   // - If you discover an existing linked in-game account, continue to sign-in
   //   the in-game account. This provides a seamless cross-device sign-in
   //   experience.
   // - If there is not an existing linked in-game account, when the user
   //   completes the sign-in using your in-game account system record the
   //   account linking with Play Games Services Recall. This helps to provide
   //   a seamless cross-device sign-in experience when the user returns on a
   //   different device or after re-installing your game on the same device.
} else {
   // Handle the error
}

ステップ 3: リコール セッション ID を処理する

ゲームが Recall セッション ID を取得してバックエンド ゲームサーバーに渡したら、Play Games サーバーサイド REST API を使用して次の操作を行います。

  • recall.retrieveTokens を使用して既存のリンク済みゲーム内アカウントをクエリする
  • recall.linkPersona を使用して、リンクされたゲーム内アカウントを追加または更新する
  • recall.unlinkPersona を使用してリンクされたゲーム内アカウントを削除する

サーバーサイド統合に関する詳細なガイドについては、ゲームサーバー内で Recall API を使用する方法に関するドキュメントをご覧ください。