Skip to main content

Android

This article guides you through setting up Facebook as an identity provider, enabling your Android game to access Player Network authentication services.

Prerequisites

1. Set up the Facebook app on Meta for Developers
1. Register for an account

Before you can configure your app for the required platforms, you need to register a Facebook developer account and create an app in the Facebook App Dashboard.

  1. Go to the Facebook website. Register for an account and finish the account authentication (by email or phone) according to the prompts.

  2. Activate a developer account in Meta for Developers.

    Image: Activate a Facebook developer account

  3. Consent to the agreement and continue.

    Image: Consent to the agreement and continue

  4. Complete mobile phone verification.

    Image: Mobile phone verification

  5. Complete email verification.

    Image: Mobile phone verification

  6. Complete the registration.

    Image: Complete registration

  7. Add Facebook SDK to the project in Meta for Developers.

2. Create an app
  1. Click Create App in the upper right corner.

    Image: Create an app

  2. Select Authenticate and request data from users with Facebook Login as the app type.

    Image: Gaming app

  3. Select Business if available, else proceed to the next step.

    Image: Gaming app

  4. Enter the basic information.
    The FACEBOOK_DISPLAYNAME in the INTLConfig.ini configuration file should be the App name here.

    Images: Enter basic information

  5. Agree and continue.

    Images: Enter basic information

3. Configure the app
caution

Follow Facebook specifications to enter the Privacy Policy URL, User Data Deletion, and Terms of Service URL. If you do not follow Facebook specifications, Facebook may disable your app after it is released.

note

For apps that have been already submitted to Facebook, they can continue to use Facebook Login For Gaming. New apps that have not been submitted are only allowed to use Facebook Login, see Facebook Login For Gaming for more information.

  1. In the left sidebar, click App Settings > Basic to view basic information about the application, such as App ID and App Secret.

    Images:Add app platform

  2. In the Privacy Policy URL field, enter the web address of the Privacy Policy.

  3. In the User Data Deletion field, select the data deletion instructions URL, and enter the web addresses according to the user's instructions for data deletion.

  4. In the Terms of Service field, Enter the URL of the Terms of Service webpage.

  5. Click Add Platform and select Android to add an Android app.

    Image: Add mobile app platform

  6. Enter the configuration directly, or click Quick Start in the top right corner of the platform configuration interface and set the configuration based on the guide.

    note

    For the Key Hashes generation method, see the official guide from Facebook.

    Image: Add platform configuration

  7. Click Save Changes to save the configuration.

Configure Facebook Login
  1. In the Facebook App Dashboard, click Use cases > Customize.
    Image: Facebook Login Windows
  2. Select Settings under Facebook Login.
  3. In Valid OAuth Redirect URIs, enter https://common-web.intlgame.com/jssdk/facebooklogincallback.html and https://test-common-web.intlgame.com/jssdk/facebooklogincallback.html.
  4. Turn on Embedded Browser OAuth Login.
    Image: Facebook Login Windows
  5. Click Save changes at the bottom of the page to save the configurations.
4. Add the testing permissions

Before the app is released, only test users or users who are added into the permission list have access to Facebook functions.

  1. In Facebook App Dashboard, click Roles.
  2. Click Add Administrators/Add Developers/Add Testers to add respective roles.

Image: Add test users

5. Verify your business

Certain Meta technologies or features require you to go through the Meta business verification. For more information, reach out to the Player Network representative.

Image: Add Test User

  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 Facebook as an authentication method for your project on Player Network Console.

Step 1: Configure the SDK for Facebook login

  1. In the AndroidManifest file, make sure the required permissions have been added. Facebook 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 = Facebook
    [Facebook]
    FACEBOOK_APP_ID = {INTL_FACEBOOK_APP_ID}
    FACEBOOK_DISPLAYNAME = {INTL_APP_NAME}
    • Set the SDK backend environment INTL_URL to 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 Facebook to LIFECYCLE. For more information, see SDK Environment.
    • Replace {INTL_FACEBOOK_APP_ID} with the Facebook App ID.
    • Replace {INTL_APP_NAME} with the name of your Facebook app.
  3. Define manifestPlaceholders in your gradle file and replace {INTL_FACEBOOK_APP_ID} with the Facebook App ID.

    mainTemplate.gradle
    android {
    defaultConfig {
    manifestPlaceholders = ["FACEBOOK_APPID":"{INTL_FACEBOOK_APP_ID}"]
    }
    }
  4. Configure ClientToken. To obtain ClientToken, go to the App Dashboard on the Facebook Developer platform, and select App settings/Advanced/Client token. For more information, see Getting Started with the Facebook SDK for Android.

    Image: ClientToken

    note

    ClientToken configuration is added for the Facebook channel to resolve the problem of the app failing when fb graph api is called too many times in a short period of time.
    This feature is effective for V1.19.03 and later versions. The following configurations are not necessary for V1.19.02 and earlier.

    Add ClientToken configuration to INTLConfig.ini.

    FACEBOOK_CLIENT_TOKEN = CLIENT-TOKEN

    Add ClientToken configuration to the projmods file.

    "FacebookClientToken":"CLIENT-TOKEN"

Step 2: Add Facebook login for your app

For Android, Player Network checks the app login state before the web login state.

  • If the Facebook app is installed, Player Network opens the Facebook app for login.
  • If the Facebook app is not installed, Player Network opens the website for login.

Player Network authentication services also supports Facebook Login for Gaming. For more information, see the Technical Implementation section of the Facebook official documentation.

  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.

    • Facebook Login

      // taking Facebook as example
      INTLAPI.Login(INTLChannel.Facebook);
    • Facebook Login for Gaming

      Call the Login method with the permission parameter to retrieve Facebook profile picture. For more information, see Requesting User's Profile Picture.

      //Add a `gaming_user_picture` permission to the original permissions string, like this: `"email,public_profile,gaming_user_picture"`
      public static void Login(string channel, string permissions = "gaming_profile,gaming_user_picture", string extraJson = "{}");
  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 Facebook 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.
  1. Configure the email permission on Meta for Developers. The email permission requires Advanced access, in order for all apps to be able to obtain player email.

    Image: Facebook permission request

  2. Add email to the permissions parameter when calling the Login API. If the permissions parameter is not specified or is empty when calling the Login API, the email permission will be added.

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