DocumentationSDKs and toolingUnityLink Google Play Games accounts

Link Google Play Games accounts

Before you configure account linking, you need to:

  1. Download and import the Google Play Games Plugin for Unity.
  2. Enable Google sign-in for your app. Follow Google’s documentation on how to configure your game for Google Login.
  3. Download and import the Stash Plugin for Unity.

1. Add Google Play Games as an ID provider

In the Webshop section of Stash Studio, add Google Play Games as an ID provider and enter your ClientId and Secret. Stash needs these values to complete the account linking process. If you don’t have your ClientId and Secret, you can find them in the Google Play console.

2. Retrieve the AuthCode

The AuthCode is required for authenticating users and linking their accounts. You use Google’s API to retrieve this auth code.

Retrieve AuthCode
private static void Login() {
  PlayGamesPlatform.Instance.Authenticate((success) => {
    if (success == SignInStatus.Success) {
      string displayName = PlayGamesPlatform.Instance.GetUserDisplayName();
      Debug.Log($"Login successful - {displayName}");
      // Fetch AuthCode using "RequestServerSideAccess"
      PlayGamesPlatform.Instance.RequestServerSideAccess(true, code => {
        // AuthCode that we need for Stash linking.
        AuthCode = code;
      });
    } else {
      Debug.Log("Login unsuccessful.");
    }
  });
}

You use Stash’s LinkGooglePlayGames method to link accounts. This method uses the AuthCode from the last step, as well as:

  • The internal user ID that’s used for purchase identification.
  • The code challenge associated with the linking request.
ℹ️

Stash recommends refreshing credentials before linking to Stash. Credentials older than 60 minutes are considered expired, which causes the linking process to fail.

Link accounts
// Wrap in try-catch block and handle StashRequestError appropriately.
try {
  LinkResponse response = await StashClient.LinkGooglePlayGames(
      _stashChallenge, InternalPlayerId, PlayGames.AuthCode);
  // Linking successful, prompt player to return back to the webshop.
} catch (StashRequestError e) {
  Debug.LogError($"[STASH][Google Play Games] Account linking failed. Code: {e.Code}, Message: {e.Message}");
}

The accounts are now linked and users are returned to the webshop to complete the flow that triggered the linking process.