Using Google Play Game Service(GPGS)
GPGS V1 is no longer supported by Google.\ If you have been using GPGS V1 or are planning to start using it, please use "Sign In with Google" instead.
GPGS V2 and "Sign In with Google" can be used under following conditions:
Category | GPGS V2 | [deprecated] GPGS V1 | Sign In with Google |
---|---|---|---|
Login information | Use PGS games_lite information | Use Google account information | Use Google account information |
Compatibility between accounts | GPGS V2 standalone Incompatible with GPGS V1 and Sign In with Google | Compatible with Sign In with Google Incompatible with GPGS V2 | Compatible with GPGS V1 Incompatible with GPGS V2 |
iOS Support | Not supported | Not supported | Supported |
::: |
- Sign in with Google account via Google Play Game Service
- Obtain a Google Access token
- Obtain a BACKND Access token by verifying the Google Access token
- Log in to the BACKND server using the BACKND Access token
- 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 to Google Play
Google Play Console Create App > Release > Production or(Public, Private, Internal) Test > Create a New Version
From Google Play App Signing, click Continue to register the app signature and issue the App Signing Key Certificate.\
Upload APK or App Bundle to issue Upload Key Certificate.\
The issued app signature can be checked from Setup > App Signing on the left. It is used to register to Google Game Service.\
2) Register to Google Game Service
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 screen to enter Google Cloud Platform.\
In Google Cloud Platform, configure the OAuth consent screen.\
Add a tester email address.
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.\
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.
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.\
Add a tester in Google Console - Play Game Service In the left menu, from Play Game Service > Tester > Release track, click Add track to 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
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!!!For GPGS version 11.01 or above, you must use GPGS V2.\ Use GPGS V1 only when using the GPGS version 10 or older.
After importing, move to the top of Unity and click Windows > Google Play Games > Setup > Android Setup
Set Resources Defintion 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.\
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
Value | Type | Description |
---|---|---|
federationToken | string | Token value created via each login plugin |
federationType | FederationType | Type of federation. (FederationType.Google) |
ect | string | (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;
}
}
ReturnCase
Success cases
When the login is successful\ statusCode : 200\ message : Success
When signing up as a new member is successful\ statusCode : 201\ message : Success
Error cases
When the account is blocked\ statusCode : 403\ errorCode : Reason for blocking entered in the console\ message : Forbidden blocked user, Blocked user
GPGS Login Error Case
Please refer to the GPGS github for errors that occur from GPGS login failures.
- GPGS github repository: https://github.com/playgameservices/play-games-plugin-for-unity
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
.