Skip to main content
Version: 5.9.6

Using Google Play Game Service(GPGS)

Flow of the process
1. Sign in with Google account via Google Play Game Service
2. Obtain a Google Access token
3. Obtain a BACKND Access token by verifying the Google Access token
4. Log in to the BACKND server using the BACKND Access token
5. Once you obtain the Access token, you can also perform the token login. For more information on tokens, refer to the relevant document.

Initial settings

1. Register the application in Google Play

Google Play Console > Create App > Release > Production or(Public, Private, Internal) Test > Create a New Version

  • 1) From Google Play App Signing, click Continue to register the app signature and issue the App Signing Key Certificate.

  • 2) Upload APK or App Bundle to issue Upload Key Certificate.

  • 3) The issued app signature can be checked from Settings > App Signing on the left. It is used to register to Google Game Service.

2. Register to Google Game Service

  • 1) On the left menu, from Play Game Service > Setup and management > Configuration, select 'No, my game doesn't use Google APIs' to create a new Play Game Service project.

  • Then, in the user authentication information, click Configure OAuth consent screento enter Google Cloud Platform.

  • 2) In Google Cloud Platform, configure the OAuth consent screen.

  • 3) Add a tester email address.

  • 4) After configuring the consent screen, click the user authentication information in the left menu to configure User Authentication Information.
    Select Create User Authentication Information > OAuth Client ID > Android.
    Repeat this process for both App Signature > App Signing Certificate and Upload Certificate registered in Step 1(Figure 4).

  • In Google Cloud Platform, a total of 2 OAuth 2.0 client IDs must be registered as follows.

  • 5) Add user authentication information to Play Game Service Add 2 pieces of Android user authentication information added to Google Cloud Platform in No. 4.

  • In Google Console, 2 pieces of user authentication information must be added as follows:

3. Set tester

To test GPGS, the tester must be registered in Google Cloud Platform and Google Console.

  • 1) Add a tester to Google Cloud Platform In the left menu of Google Cloud Platform, click OAuth consent screen > Test user > +ADD USERS to register a tester.
  • 2) Add a tester in Google Console - Play Game Service In the left menu, from Play Game Service > Tester > Release track, click Add trackto add a track where the app is published.
  • After that, in the Tester field, click Add tester to add a tester(must be identical to the tester added in Google Cloud Platform.)

4. Set Unity

1) Unity Project - Add Google Play Games Services Plugin https://github.com/playgameservices/play-games-plugin-for-unity

Download GPGS version 10 > \[current-build] folder > unitypackage import
Caution!!!
The latest updated version of GPGS is not supported yet.
Please use GPGS version 10 before an update is available to address the issue.

After importing, move to the top of Unity and click Windows > Google Play Games > Setup > Android Setup

2) Set Resources Definition

  • From Play Game Service > Setup and management > Configuration > Credentials, click View resource on the right.
  • Copy Android(XML) and paste into Unity GPGS Setting Window - Resources Definition.

3) Set Client ID

  • In the relevant project, click Google Cloud Platform > Credentials > +Create credentials.
  • Set the application type as web application and create it.
  • Copy the client ID of the created web application and paste it to Unity GPGS Setting Window - Client ID.

All settings required to obtain the ID token are finished. You can obtain the ID token using the ID registered in Google Play console.
If you wish to test another ID, you can do so by adding another tester through #3. Set tester.


AuthorizeFederation

public BackendReturnObject AuthorizeFederation(string federationToken, FederationType type);
public BackendReturnObject AuthorizeFederation(string federationToken, FederationType type, string ect);

Parameters

ValueTypeDescription
federationTokenstringToken value created via each login plugin
federationTypeFederationTypeType of federation.(FederationType.Google)
ectstring(Optional) The piece of information desired to be saved from the additional information

Description

An attempt is made to sign up or log in using the Google member information token value.

To obtain the ID token of Google Play Game Services(GPGS), change the default setting of PlayGamesClientConfiguration to custom and execute GPGS.

When the Google account logs into the game(sign-up) for the first time, Google token's value may be returned as null. You can receive a normal token value by requesting again.

Example

// GPGS login 
void Start(){
// GPGS plugin setting
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration
.Builder()
.RequestServerAuthCode(false)
.RequestEmail() // If you do not want to obtain email permission, delete the relevant line(RequestEmail).
.RequestIdToken()
.Build();
//Reset GPGS using the customized information
PlayGamesPlatform.InitializeInstance(config);
PlayGamesPlatform.DebugLogEnabled = true; // If you do not want to see the debug log, change it to 'false.'
//Launch GPGS.
PlayGamesPlatform.Activate();
}

public void GPGSLogin()
{
// When you are already signed in
if(Social.localUser.authenticated == true)
{
BackendReturnObject BRO = Backend.BMember.AuthorizeFederation(GetTokens(), FederationType.Google, "gpgs");
}
else
{
Social.localUser.Authenticate((bool success) => {
if(success){
// Successfully signed in -> Requests sign-up to BACKND server using the obtained Google token
BackendReturnObject BRO = Backend.BMember.AuthorizeFederation(GetTokens(), FederationType.Google, "gpgs");
}
else
{
// Sign-in failed
Debug.Log("Login failed for some reason");
}
});
}
}

// Google token is received
public string GetTokens()
{
if(PlayGamesPlatform.Instance.localUser.authenticated)
{
// First way of receiving a user token
string _IDtoken = PlayGamesPlatform.Instance.GetIdToken();
// Second way
// string _IDtoken = ((PlayGamesLocalUser)Social.localUser).GetIdToken();
return _IDtoken;
}
else
{
Debug.Log("Not connected. PlayGamesPlatform.Instance.localUser.authenticated: fail");
return null;
}
}

Return cases

Success cases

When the login is successful
statusCode : 200

When signing up as a new member is successful
statusCode : 201

Error cases

When the account is blocked
statusCode : 403
errorCode : Reason for blocking entered in the console


GPGS login error case

Please refer to the GPGS github for errors that occur from GPGS login failures.

When the app closes upon trying to sign in to GPGS

Application ID(1040339826718) must be a numeric value. Please verify that your manifest refers to the correct project ID.

If the above error occurs, go to Assets > GooglePlayGames > Plugins > Android > GooglePlayGamesManifest > AndroidManifest.xml, find meta-data android:name="com.google.android.gms.games.APP_ID", and change the corresponding value's \ to \u003.