Android
This article guides you through setting up Twitter as an identity provider, enabling your Android game to access Player Network authentication services.
Prerequisites
1. Set up the Twitter app on Twitter Developer Platform
1. Create a Twitter app
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.
Create a new project.
Select a use case. Click Next.
Enter the project description. Click Next.
Select the application environment. Click Save.
Enter the app name. Click Save.
Obtain the API key and API secret key after creating an app. Store this information. Click App Settings.
cautionThis is the last time you will see this screen. Do store this information.
Click Set up.
Enable OAuth2.0 and OAuth1.0a. Select Web App for Type Of App.
Select Read And Write for App Permissions.
For callback URLs, enter the testing environment and production environment URLs. You will enter the game's official website. Click Save.
If the game is already online, the existing callback URLs cannot be deleted, only added.
For 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
For 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 {}.
2. Retrieve app information
You need the Twitter app ID and secret to add Twitter as a login channel on Player Network.
- 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 Twitter as an authentication method for your project on Player Network Console.
Step 1: Configure the SDK for Twitter login
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 = Twitter
[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 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 Twitter in
LIFECYCLE
. For more information, see SDK Environment. - Replace
{INTL_TWITTER_CONSUMER_KEY}
and{INTL_TWITTER_CONSUMER_SECRET}
with the Twitter API key and API Key Secret.
- Set the SDK backend environment to
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.
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.Twitter);
UINTLSDKAPI::Login(EINTLLoginChannel::kChannelTwitter);
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.
Under User authentication settings in the Twitter Developer Platform, enable Request email from users.
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.