Android
This article guides you through setting up Google as an identity provider, enabling your Android game to access Player Network authentication services.
Prerequisites
1. Set up the Google app on the Google Play Console
For IEGG projects, contact [miaruan (Ruan Mingjun)] for Google app registration and configuration.
1. Create a Google app
Register an account on Google Play Console following the prompts.
Google charges a fee of 25USD for the service. Please prepare a credit card in advance.
Go to the Google Play Console.
On the All apps page, click Create app to create a game app.
Enter the app information.
2. Create a Play Games Services game project
Set up Play Games Services to manage game metadata and automate game production and distribution tasks.
Go to Google Play Console.
On the left navigation bar, select Grow > Play Games Services > Setup and management > Configuration.
Under Does your game already use Google APIs, select the correct answer and your Play Games Services game project is created.
In the Properties section, click Edit Properties.
Enter basic game information and click Save changes.
3. Add a credential to link the OAuth 2.0 client ID to your game
Go to Google Cloud Platform.
On the left navigation bar, click OAuth consent screen.
Follow the instructions to setup the OAuth consent screen.
On the left navigation bar, click Credentials.
On the Credentials page, select CREATE CREDENTIALS > OAuth Client ID to create an OAuth client ID.
In the Application type list, click Android.
Enter the Package Name and SHA-1 Certificate Fingerprint.
Confirm the Package Name and SHA-1 Certificate Fingerprint with the development team. The OAuth client for Android requires users to configure the SHA-1 certificate fingerprint and package name in the KeyStore. Make sure the two values are correct. Otherwise, the login process will throw an exception.Click SAVE to complete the configuration.
Go to the details page of the Android app and check the Client ID and Client Secret.
Add login test users.
4. Configure for API access
Go to Google Cloud Platform.
On the left navigation bar, select Settings > Developer account > API access.
One the API access page, accept the Terms of Service.
Click Link on the right of the corresponding project to link Google Play Console to the API project.
5. Add testers for your game
Go to Google Play Console.
On the left navigation bar, select Grow > Play Games Services > Setup and management > Testers.
In the Testers tab, click Add testers to add testers for your game.
Before the game app is released, only testers can log in. Please make sure that the app is in the testing status.
6. Configure Achievements and Leaderboards
Find the Achievements and Leaderboards functions in the Play Games services menu and configure them as needed.
7. Get Google API ID
Access the Information Center from the Google Cloud Platform dashboard. The Google API ID is the Project No. on this page.
8. Get the Client ID and Client secret
Follow the steps in Add a credential to link the OAuth 2.0 client ID to your game to get the application information.
- Create an account for Player Network Console.
- Create a new project for your game, or join an existing one.
- Download the SDK.
- Integrate the SDK.
- Add Google as an authentication method for your project on Player Network Console.
Step 1: Configure the SDK for Google login
In the
AndroidManifest
file, make sure the required permissions have been added. Google requires access to the network.<uses-permission android:name="android.permission.INTERNET"/>
Open the project's INTLConfig.ini:
INTLConfig.ini[INTL environment]
# WARNING: You should change this URL to the production environment when you release your game.
INTL_URL = https://test.intlgame.com
GAME_ID = {INTL_GAME_ID}
SDK_KEY = {INTL_SDK_KEY}
[INTL Log]
LOG_LEVEL = 1
LOG_CONSOLE_OUTPUT_ENABLE = 1
LOG_FILE_OUTPUT_ENABLE = 1
LOG_ENCRYPT_ENABLE = 0
LOG_COMPRESS_ENABLE = 0
[Android LifeCycle]
LIFECYCLE = Google
[Google]
GOOGLE_CLIENT_KEY_ANDROID = {INTL_GOOGLE_CLIENT_KEY}- Set the SDK backend environment to
INTL_URL = https://test.intlgame.com
. - Replace
{INTL_GAME_ID}
and{INTL_SDK_KEY}
with theGAME_ID
andSDK_KEY
assigned by Player Network Console. - Set
LOG_LEVEL = 1
,LOG_CONSOLE_OUTPUT_ENABLE = 1
,LOG_FILE_OUTPUT_ENABLE = 1
,LOG_ENCRYPT_ENABLE = 0
, andLOG_COMPRESS_ENABLE = 0
to output console logs and log files without encrypting or compressing the output. - Add Google to
LIFECYCLE
. For more information, see SDK Environment. - Replace
{INTL_GOOGLE_CLIENT_KEY}
with the Web client Key.
It is the client ID for web applications in the Credentials section during API OAuth configuration, also known as Server Client ID during API OAuth 2.5 configuration.
- Set the SDK backend environment to
Define
manifestPlaceholders
in your gradle file by replacing{INTL_GOOGLE_APP_ID}
with the Google App ID.- Unity
- Unreal Engine
mainTemplate.gradleandroid {
defaultConfig {
manifestPlaceholders = ["GOOGLE_APPID":"{INTL_GOOGLE_APP_ID}"]
}
}noteFor Player Network SDK V1.17 or later, edit
INTLConfig_APL.xml
.For Player Network SDK V1.16.04 or earlier, edit
INTLCore_UPL.xml
.<buildGradleAdditions>
<insert>
<![CDATA[
android{
defaultConfig {
manifestPlaceholders = ["GOOGLE_APPID":"{INTL_GOOGLE_APP_ID}"]
}
}]]>
</insert>
</buildGradleAdditions>
Step 2: Add Google login
All Google operations require a connection to Google services.
Automatic Login (AuthLogin)
During automatic login, the device may be unable to connect to Google services. By default, Player Network SDK connects to Google services upon automatic login, which is recommended. (Game teams can disable the connection by configuring the GOOGLE_LOGOUT_NEED_CONNECT
field as instructed in the Google Channel Configuration
section of the INTLConfig
file.)
Login
Before calling Google login, Player Network SDK will check if Google Mobile Services (GMS) is available. The login service can be called only when GMS is available. If GMS is unavailable, Player Network SDK will return the error code returned by Google to games through the ThirdCode
field of INTLAuthResult
.
Return code | Value | Error Description |
---|---|---|
SERVICE_MISSING | 1 | The GMS is unavailable on the device. |
SERVICE_VERSION_UPDATE_REQUIRED | 2 | The installed GMS version has expired. |
SERVICE_DISABLED | 3 | The GMS is disabled. |
SERVICE_INVALID | 9 | The installed GMS version is incorrect. |
SERVICE_UPDATING | 18 | The GMS is being updated on the device. |
For more information, see Google Docs and Google FAQs
Add an observer to handle authentication callbacks.
- Unity
- Unreal Engine
// Add callbacks
public void AddAuthObserver()
{
INTLAPI.AddAuthResultObserver(OnAuthResultEvent);
}
// Remove callbacks
public void RemoveAuthObserver()
{
INTLAPI.RemoveAuthResultObserver(OnAuthResultEvent);
}
// Process the INTLAuthResult callback
public void OnAuthResultEvent(INTLAuthResult ret)
{
Debug.Log($"MethodID: {ret.MethodId}");
string methodTag = "";
if (authRet.MethodId == (int)INTLMethodID.INTL_AUTH_LOGIN)
{
methodTag = "Login";
}
else if (authRet.MethodId == (int)INTLMethodID.INTL_AUTH_BIND)
{
methodTag = "Bind";
}
else if (authRet.MethodId == (int)INTLMethodID.INTL_AUTH_AUTOLOGIN)
{
methodTag = "AutoLogin";
}
else if (authRet.MethodId == (int)INTLMethodID.INTL_AUTH_QUERY_USER_INFO)
{
methodTag = "QueryUserInfo";
}
else if (authRet.MethodId == (int)INTLMethodID.INTL_AUTH_GET_AUTH_RESULT)
{
methodTag = "GetAuthResult";
}
}C++ Event Handling (above v1.15)
//configure callback
FINTLAuthEvent authEvent;
authEvent.AddUObject(this, &OnAuthResult_Implementation);
UINTLSDKAPI::SetAuthResultObserver(authEvent);
// Remove callbacks
UINTLSDKAPI::GetAuthResultObserver().Clear();void OnAuthResult_Implementation(FINTLAuthResult ret)
{
UE_LOG(LogTemp, Warning, TEXT("MethodID: %d"), ret.MethodId);
}Unreal Event Handling
void OnAuthResult_Implementation(FINTLAuthResult ret)
{
UE_LOG(LogTemp, Warning, TEXT("MethodID: %d"), ret.MethodId);
}Call the
AutoLogin
method.- Unity
- Unreal Engine
INTLAPI.AutoLogin();
UINTLSDKAPI::AutoLogin();
Call the
Login
method to ask for user input if auto-login fails.- Unity
- Unreal Engine
INTLAPI.Login(INTLChannel.Google);
UINTLSDKAPI::Login(EINTLLoginChannel::kChannelGoogle);
Sync client authentication state with the game's backend and wait for the final authentication result.
[Optional] Set up email permissions
Set up permissions to obtain the email address of players during Google login, returned as email
in the ChannelInfo
of AuthResult
.
- Email masking can be performed on the returned
email
according to compliance requirements, reach out to the Player Network representative to enable this feature. - The hashed
base64(sha256(email))
can be reported to the backend logs, reach out to the Player Network representative to enable this feature. - Can be used to verify if
email
is present in a player's profile or third-party channel information, reach out to the Player Network representative to enable this feature.
Enable email return on Player Network Console by setting return_email to YES, see Configure Third-party Channels for detailed procedures.
Step 3: Test the login function
Search for the keyword "AuthResult" in the Player Network SDK logs to verify if the correct channel name and OpenID are returned. If they are, it indicates a successful configuration and the login function has been added successfully.
Step 4: Release your game
Before preparing for a production release, create a testing release with Android App Bundle.
The advantage of releasing a Beta version is that users can download it from Google play, but have no permission to add comments. A specific channel is set for users to submit feedback.
Create a production release
Go to Google Play Console.
On the left navigation bar, select Release > Production.
Follow the instructions to create the production release.
Change the publishing status
If users do not release the app, authentication may fail.
Go to the OAuth consent screen page of Google Cloud Platform.
Change the Publishing status to PUBLISH APP.
Use an APK to test Google login
For more information, see Use an APK to test Google login.
Use Google Play Games Services to synchronize login status
For games intending to integrate with Google Play Games on PC, Google Play Games Services (GooglePGS) is recommended to be used to synchronize the login status of the game on the Android device to Google Play Games on PC.
To use GooglePGS to synchronize the login status, both INTLGoogle
and INTLGooglePGS
will have to be integrated.
Step 1: Configure the SDK for GooglePGS
In the project's INTLConfig.ini file, add the following configuration:
INTLConfig.ini[Android LifeCycle]
LIFECYCLE = GooglePGS
[GooglePGS]
GOOGLEPGS_SERVER_PROJECT_ID = {INTL_GOOGLEPGS_SERVER_PROJECT_ID}
GOOGLEPGS_ENABLE_PGS = 1- Replace
{INTL_GOOGLEPGS_SERVER_PROJECT_ID}
with the secret key for the web client.
This is the client ID for the web app from the Credentials section when configuring API OAuth, also known as the server client ID when configuring API OAuth 2.5. GOOGLEPGS_ENABLE_PGS
controls whether the SDK uses GooglePGS to synchronize the login status to Google Play Games on PC, withGOOGLEPGS_ENABLE_PGS = 1
being enabled.
- Replace
Define
manifestPlaceholders
in your gradle file by replacing{INTL_GOOGLEPGS_APP_ID}
with the Google App ID.- Unity
- Unreal Engine
mainTemplate.gradleandroid {
defaultConfig {
manifestPlaceholders = ["GOOGLEPGS_APPID":"{INTL_GOOGLEPGS_APP_ID}"]
}
}noteFor Player Network SDK V1.17 or later, edit
INTLConfig_APL.xml
.For Player Network SDK V1.16.04 or earlier, edit
INTLCore_UPL.xml
.<buildGradleAdditions>
<insert>
<![CDATA[
android{
defaultConfig {
manifestPlaceholders = ["GOOGLEPGS_APPID":"{INTL_GOOGLEPGS_APP_ID}"]
}
}]]>
</insert>
</buildGradleAdditions>
Step 2:Use AutoLogin
to obtain login status on Google Play Games on PC
After completing the steps above, GooglePGS can be used to synchronize the login status of the game on the Android device to Google Play Games on PC. The same Google account must be used on both the Android device and on Google Play Games on PC.
- Unity
- Unreal Engine
INTLAPI.AutoLogin();
UINTLSDKAPI::AutoLogin();