# Google Play Games

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

### Prerequisites

* [A LootLocker account](https://lootlocker.com/sign-up)
* [An existing game in the Web Console](https://console.lootlocker.com/)
* [Google Play Games Platform enabled in the Web Console](https://console.lootlocker.com/settings/platforms/google_play_games)
* [An account and game setup in the Google Play Developer Console](https://play.google.com/console/developers)
* [Play Games Services setup for your game](https://developer.android.com/games/pgs/console/setup)

### Configure Google Play Games

First, navigate to the [Platform Settings for Google Play Games](https://console.lootlocker.com/settings/platforms/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](https://console.cloud.google.com/auth/clients), 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.

* [Client ID](#client-id)
* [Client Secret](#client-secret)
* [App ID](#app-id)

<figure><img src="https://534367586-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVu1MPzezO-NgvC98xh%2Fuploads%2Fgit-blob-2193cbbc4dd7c16431a29ef90561744140ef6cbd%2Fgoogle_play_games_web_console_fields.png?alt=media" alt=""><figcaption></figcaption></figure>

### Authenticating with Google Play Games in your game

LootLocker supports [Google Play Games v2](https://developer.android.com/games/pgs/start), if your game is running v1 of Google Play Games, you must [migrate](https://developer.android.com/games/pgs/migration_overview) to v2.

#### Starting a session

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

{% tabs %}
{% tab title="Unity" %}
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.

```csharp
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);
            }
        });
    }
}
```

{% endtab %}

{% tab title="Unreal Blueprints" %}
Coming soon
{% endtab %}

{% tab title="Unreal C++" %}
Coming soon
{% endtab %}

{% tab title="REST" %}

```bash
curl --location --request POST 'https://api.lootlocker.com/game/session/google-play-games/v1/login' \
--header 'Content-Type: application/json' \
--data-raw '{
    "game_api_key": "string",
    "auth_code": "string",
    "game_version": "string",
    "optionals": {
        "timezone": "string",
        "player_name": "string"
    }
}'
```

Example response:

```json
{
    "session_token": "string",
    "player_identifier": "string",
    "player_id": 0,
    "player_name": "string",
    "player_ulid": "string",
    "player_created_at": "string",
    "public_uid": "string",
    "seen_before": true,
    "check_grant_notifications": true,
    "check_deactivation_notifications": true,
    "check_dlcs": [
        "string"
    ],
    "success": true
}
```

{% endtab %}
{% endtabs %}

### 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](https://docs.lootlocker.com/the-basics/core-concepts).
