Skip to content

Google Play Games

This how-to walks you through authenticating and setting up Google Play Games for your game.

Prerequisites

Configure Google Play Games

First, navigate to the Platform Settings for Google Play Games in the LootLocker Web Console.

Client ID

In the Google Play Developer Console, navigate to Play Games Services -> Setup and management -> Configuration and copy the Client ID and paste it into the Client ID field in the LootLocker Web Console.

Client Secret

Go to the Google Cloud Console, navigate to the OAuth2-part of your app and generate a new secret key or create a new Oauth client with a Web Client configuration. Download the Client Secret and store it in a safe place, copy the Client Secret and paste it into the Client Secret field in the LootLocker Web Console.

App ID

In the Google Play Developer Console, navigate to Play Games Services -> Setup and management -> Configuration and copy the Project ID and paste it into the App ID field in the LootLocker Web Console.

After all credentials have been added, click Save in the LootLocker Web Console. Google Play Games is now fully configured in the Web Console and ready to be used in your game.

Web Console Setup

Now, verify that all information that is in their respective input fields.

Authenticating with Google Play Games in your game

LootLocker supports Google Play Games v2, if your game is running v1 of Google Play Games, you must migrate to v2.

Starting a session

When signing in with Google Play Games, you need to add the OPEN_ID-scope when requesting the token.

Make sure that you have the Google Play Games v2 SDK properly installed and setup before adding any code.

This code serves as an example, make sure to add any error handling that your game might require.

using UnityEngine;
using GooglePlayGames;
using GooglePlayGames.BasicApi;
using LootLocker.Requests;
using System.Collections.Generic;
public class GoogleSignIn : MonoBehaviour
{
// Example of activating Google Play Games and starting a session with LootLocker
public void Start()
{
PlayGamesPlatform.Activate();
PlayGamesPlatform.Instance.Authenticate((response) =>
{
if (response == GooglePlayGames.BasicApi.SignInStatus.Success)
{
// Add desired scopes for server-side access
List<AuthScope> scopes = new List<AuthScope>
{
AuthScope.OPEN_ID
};
PlayGamesPlatform.Instance.RequestServerSideAccess(true, scopes, (google) =>
{
if (google != null)
{
string token = google.GetAuthCode();
LootLockerSDKManager.StartGooglePlayGamesSession(token, (response) =>
{
if (response.success)
{
Debug.Log("Successfully started LootLocker session with Google Play Games.");
}
else
{
Debug.Log("LootLocker Google Play Games session failed: " + response.Error);
}
});
}
else
{
Debug.Log("Google server-side access request failed.");
}
});
}
else
{
Debug.Log("Google Play Games authentication failed: " + response);
}
});
}
}

Conclusion

In this how-to we have set up and enabled Google Play Games. Your game is now fully setup to integrate any of our other available features.