Skip to main content

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
note

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.

info

Google charges a fee of 25USD for the service. Please prepare a credit card in advance.

  1. Go to the Google Play Console.

  2. On the All apps page, click Create app to create a game app.

    Image: Google - create a game app

  3. Enter the app information.

    Image: Google - enter information for the app

2. Create a Play Games Services game project

Set up Play Games Services to manage game metadata and automate game production and distribution tasks.

  1. Go to Google Play Console.

  2. On the left navigation bar, select Grow > Play Games Services > Setup and management > Configuration.

  3. Under Does your game already use Google APIs, select the correct answer and your Play Games Services game project is created.

    Image: Google service creation

  4. In the Properties section, click Edit Properties.

  5. Enter basic game information and click Save changes.

    Image: Google basic game information

3. Add a credential to link the OAuth 2.0 client ID to your game
  1. Go to Google Cloud Platform.

  2. On the left navigation bar, click OAuth consent screen.

  3. Follow the instructions to setup the OAuth consent screen.

    Image: Google, consent to the agreement

  4. On the left navigation bar, click Credentials.

  5. On the Credentials page, select CREATE CREDENTIALS > OAuth Client ID to create an OAuth client ID.

    Image: Google, create OAuth clients

  6. In the Application type list, click Android.

  7. 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.

    Image: Google, create an Android client

  8. Click SAVE to complete the configuration.

  9. Go to the details page of the Android app and check the Client ID and Client Secret.

  10. Add login test users.

    Image: Google, add test users

4. Configure for API access
  1. Go to Google Cloud Platform.

  2. On the left navigation bar, select Settings > Developer account > API access.

    Image: Google API console

  3. One the API access page, accept the Terms of Service.

  4. Click Link on the right of the corresponding project to link Google Play Console to the API project.

5. Add testers for your game
  1. Go to Google Play Console.

  2. On the left navigation bar, select Grow > Play Games Services > Setup and management > Testers.

  3. In the Testers tab, click Add testers to add testers for your game.

    Image: Google testers

note

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.

Image: Google leaderboard

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.

Image: Google ID

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.

Image: Google Web Client ID and Secret

  1. Create an account for Player Network Console.
  2. Create a new project for your game, or join an existing one.
  3. Download the SDK.
  4. Integrate the SDK.
  5. Add Google as an authentication method for your project on Player Network Console.

Step 1: Configure the SDK for Google login

  1. 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"/>
  2. 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 the GAME_ID and SDK_KEY assigned by Player Network Console.
    • Set LOG_LEVEL = 1, LOG_CONSOLE_OUTPUT_ENABLE = 1, LOG_FILE_OUTPUT_ENABLE = 1, LOG_ENCRYPT_ENABLE = 0, and LOG_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.
  3. Define manifestPlaceholders in your gradle file by replacing {INTL_GOOGLE_APP_ID} with the Google App ID.

    mainTemplate.gradle
    android {
    defaultConfig {
    manifestPlaceholders = ["GOOGLE_APPID":"{INTL_GOOGLE_APP_ID}"]
    }
    }

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 codeValueError Description
SERVICE_MISSING1The GMS is unavailable on the device.
SERVICE_VERSION_UPDATE_REQUIRED2The installed GMS version has expired.
SERVICE_DISABLED3The GMS is disabled.
SERVICE_INVALID9The installed GMS version is incorrect.
SERVICE_UPDATING18The GMS is being updated on the device.

For more information, see Google Docs and Google FAQs

  1. Add an observer to handle authentication callbacks.

    // 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";
    }
    }
  2. Call the AutoLogin method.

    INTLAPI.AutoLogin();
  3. Call the Login method to ask for user input if auto-login fails.

    INTLAPI.Login(INTLChannel.Google); 
  4. 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
  1. Go to Google Play Console.

  2. On the left navigation bar, select Release > Production.

    Figure: Select corresponding channel

  3. Follow the instructions to create the production release.

    Image: Google beta testing

Change the publishing status
caution

If users do not release the app, authentication may fail.

  1. Go to the OAuth consent screen page of Google Cloud Platform.

  2. Change the Publishing status to PUBLISH APP.

    Image: Google app release

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

  1. 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, with GOOGLEPGS_ENABLE_PGS = 1 being enabled.
  2. Define manifestPlaceholders in your gradle file by replacing {INTL_GOOGLEPGS_APP_ID} with the Google App ID.

    mainTemplate.gradle
    android {
    defaultConfig {
    manifestPlaceholders = ["GOOGLEPGS_APPID":"{INTL_GOOGLEPGS_APP_ID}"]
    }
    }

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.

INTLAPI.AutoLogin();