Skip to main content

iOS

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

caution

From Spring 2024, developers will have to clearly describe data use in the privacy manifest, showing how required reason APIs will be utilized in apps that are updated or uploaded to Apple App Store Connect. For more information, see Upcoming third-party SDK requirements.

As Twitter has yet to publish their privacy manifest, such content is not available in the Player Network SDK privacy manifest, see iOS 17 Privacy Manifest for more information.

note

As Player Network SDK only supports Twitter web login, the INTLTwitter plugin depends on the INTLWKWebViewJavascriptBridge of the WebView component to retrieve login information returned by the Twitter login webpage.

Prerequisites

1. Set up the Twitter app on the Twitter Developer Platform

1. Create a Twitter app

info

It is recommended to register an account with a Tencent email address, which can increase the success rate of later applications.

Register a team developer account or individual developer account on the Twitter developer website according to the prompts. With a developer account, you can create your app in the Developer Portal.

  1. Create a new project.

    Image: Create Twitter project

  2. Select a use case. Click Next.

    Image: Twitter project use case

  3. Enter the project description. Click Next.

    Image: Twitter project description

  4. Select the application environment. Click Save.

    Image: Twitter application environment

  5. Enter the app name. Click Save.

    Image: Twitter app name

  6. Obtain the API key and API secret key after creating an app. Store this information. Click App Settings.

    caution

    This is the last time you will see this screen. Do store this information.

    Image: Twitter API key and API secret key

  7. Click Set up.

    Image: Twitter setup

  8. Enable OAuth2.0 and OAuth1.0a. Select Web App for Type Of App.

    Image: Twitter OAuth

  9. Select Read And Write for App Permissions.

    Image: Twitter app permissions

  10. For callback URLs, enter the testing environment and production environment URLs. You will enter the game's official website. Click Save.

caution

If the game is already online, the existing callback URLs cannot be deleted, only added.

Player Network SDK V1.15 and earlier

https://image.intlgame.com/v2/test/jssdk/twitterlogincallback.html
https://image.intlgame.com/v2/release/jssdk/twitterlogincallback.html

Player Network SDK V1.16 and later

https://test-common-web.intlgame.com/jssdk/twitterlogincallback.html
https://common-web.intlgame.com/jssdk/twitterlogincallback.html

To log in with the Twitter SDK in INTLConfig.ini when TWITTER_CONSUMER_USE_SDK is 1, add the following callback URL:

twittersdk://
twitterkit-{API Key}://

{API Key} needs to be replaced with the API Key of the game, excluding curly brackets {}.

Image: Twitter callback URLs

2. Retrieve app information

You need the Twitter app ID and secret to add Twitter as a login channel on Player Network.

Image: Twitter app information

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

Step 1: Configure the SDK for Twitter login

  1. Open the INTLConfig.ini file.

    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
    [Twitter]
    TWITTER_CONSUMER_KEY = {INTL_TWITTER_CONSUMER_KEY}
    TWITTER_CONSUMER_SECRET = {INTL_TWITTER_CONSUMER_SECRET}
    • 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.
    • Replace {INTL_TWITTER_CONSUMER_KEY} and {INTL_TWITTER_CONSUMER_SECRET} with the Twitter API key and API Key Secret.
  2. Add Twitter to the Info.plist file.

    Check the predefined values in INTLTwitterKit.projmods and replace {INTL_TWITTER_CONSUMER_KEY} with the Twitter API Key before exporting the Xcode project from Unity.

    {
    "group": "INTL",
    "Info.plist":{
    "LSApplicationQueriesSchemes":
    [
    "twitter",
    "twitterauth",
    ],
    "CFBundleURLTypes" :
    [
    {
    "CFBundleTypeRole":"Editor",
    "CFBundleURLSchemes":["twitterkit-{INTL_TWITTER_CONSUMER_KEY}"]
    }
    ]
    }
    }

    Replace {INTL_TWITTER_CONSUMER_KEY} with the Twitter API Key.

    If there is a need to call Twitter friends, in INTLTwitter’s iOS plugin, find the BuildPhrases configuration of the project in the Xcode project, and add or modify the following configuration:

    MapKit.framework
    Accounts.framework
    CoreData.framework

Step 2: Add Twitter login

After logging in, select Twitter Channel to link it. If a user used a linked Twitter account, a server error will be displayed. Calling the Bind method again will require the user to log in to Twitter again.

  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.Twitter); 
  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 Twitter 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.
  • Can be used to enable Private Set Membership (PSM) for Firebase on iOS, see Firebase iOS configurations for more details.
  1. Under User authentication settings in the Twitter Developer Platform, enable Request email from users.

    Image: OAUTH1.OA SETTINGS
  2. 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.