Google Link and Login

Similar to the Facebook Login, you can also link a Google account with a ChilliConnect account. Linking either Facebook or Google to a ChilliConnect account is the primary way to ensure you do not lose any Player data when switching device, or during a re-install.

This tutorial covers the following:

  • Setting up a Google Play Services Web Application and relevant OAuth2 Client Information.
  • Setting up Google Play Services Plugin with Unity
  • Attaching a Google Account to a ChilliConnect account to allow for Google Play logins.

Configuring Google Play Services

This tutorial assumes you already have an Android Application configured in the Google Play Services Console. If not, you can follow the Google Documentation to create and configure your first Android Application.

In order for Google Play Services to return an AuthCode for use in linking the Players account, there needs to be another Web Application type configured in the Console, then linked to the original Android App.

  • Open your Android Application Details page on the Play Console, and navigate to "Linked apps".
  • You will have the option to "Link another app", via a dropdown list at the top of the modal. Select this dropdown, and select "Web".
  • On this screen you will see some basic information about the App. You have the option to enter a Launch URL here, enter "". Multiplayer settings are not needed.
  • Fill in this detail and continue.

The next screen will present you with the ability to "Authorise Your App". This is the stage that you will be given OAuth Keys and other needed configuration

When you select the "Authorise Your App" link, a modal will appear containing URL information. These URLs are not important at this time. Proceed past the confirmation screen and you will be given an OAuth2 Client ID.

You should now have a Web Application linked to your main Android application, allowing AuthCode to be returned with Authentication calls to Google Play Services. The remaining information that ChilliConnect will need is contained on the Google Developers Console, so follow the link given to you by the Success screen.

In the Google Developers Console, you should now see another Application alongside your Android App with the Type listed as "Web Application".

Select the item from the list with type "Web Application" and you should be taken to a screen containing both ClientID and Client Secret. These are the two values that ChilliConnect needs, it's also of importance to note that this has to be a Web Application type linked to your Android Application or the AuthCode will not be returned.

Navigate to your ChilliConnect Dashboard. On the main "Game" page, navigate to the "Settings" tab, and scroll down to access the Google OAuth Tokens area. Select "Edit ClientID".

Enter the ClientID and Secret here.

That's all for configuring your Web Application and ChilliConnect Dashboard. Google Play Services still needs to be integrated into Unity alongside some configuration.

Configuring Unity

The Google Play Services Plugin for Unity is what we are going to be using to connect a Google Account with ChilliConnect. Download the latest stable build from GitHub and import it into your project.

When the Plugin has been successfully imported you should see a new Menu option under "Window" called Google Play Games. Navigate through "Setup" > "Android Setup..."

In this dialog we will need to enter some XML into a text; both the ApplicationID (which can be found in the Google Player Developer Console under the main Game Name header), as well as the package name; either obtained via Android.Manifest or from Google Play Console. This is also where the Web Application ClientID is entered. It's important that the Web Application you just created is entered in here, not the Android Application ClientID. Selecting "Setup" will trigger a quick settings check.

It's worth mentioning that the XML needed for the Android Setup Menu does not have to be hand coded; if you have Achivements configured in your game, you should be able to select the "Get resources" link to get an XML export of important game details.

Ensure that the package name (configurable in the "Player Settings..." -> "Other Settings") matches the package name you configured in the console, as well as the keystore location configured.

Ensure your project can be built and Google Play Services should now be incorporated into Unity.

Retrieve AuthCode

The process of getting an AuthCode from google is relatively simple after everything has been configured correctly. Make sure you are using the correct "using" statements in the class that deals with Authentication;

using GooglePlayGames;
using GooglePlayGames.BasicApi;
using UnityEngine.SocialPlatforms;

First we have to configure the builder before any connect request is made. We need to request the Service AuthCode as well as the IdToken when loading the configuration;

PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
         //configure basic profile access so ChilliConnect can access the player name.
         // requests a server auth code and an IdToken to be returned

PlayGamesPlatform.DebugLogEnabled = true;

// activate Google Play Platform with the above config

We now have access to the PlayGamesPlatform, and are ready to Authenticate. Authentication is actually handled by the Social Unity library, but after this has finished we can call "GetServerAuthCode()" to get a copy of the AuthCode ChilliConnect will need.

Important: AuthCodes can be authenticated once only. If you have already used an AuthCode to link a Player, that AuthCode cannot be redeemed again.

Social.localUser.Authenticate((bool success) =>
            if (success)
                Debug.Log("UserName:" + Social.localUser.userName);
                Debug.Log("Id Token:" + PlayGamesPlatform.Instance.GetIdToken());
                Debug.Log("AuthCode:" + PlayGamesPlatform.Instance.GetServerAuthCode());
            } else
                Debug.Log("Authentication Has Failed. Re-check configuration.");

If authentication is unsuccessful, or if AuthCode is being returned as null that typically means an configuration has gone wrong somewhere, therefore check the Applications have been linked correctly in the Google Play Console, as well as all details being entered correctly into Unity IDE, as well as ChilliConnect Dashboard.