Skip to main content

Web

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

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.

    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.

Android/iOS Platforms for Player Network SDK 1.15 and earlier

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

Android/iOS Platforms for Player Network SDK 1.16 and later, and Windows Platform

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

For more details about integrating the SDK for other third-party channels, see JavaScript SDK.

Step 1: Install the JavaScript SDK

Install the JavaScript SDK from npm or CDN.

$ npm install @intlsdk/account-api
// SDK production version package
<script src="https://common-web.intlgame.com/sdk-cdn/account-api/latest/index.umd.js"></script>

Step 2: Instantiate the SDK

caution

Set env to the test environment during the integration testing and env to the corresponding production environment when launching the game.

const accountApi = new IntlgameAccountApi({
env: "test", // SDK environment
gameID: 11,
});
ParameterTypeDescriptionRemark
envstringSDK environment
For more information, see Retrieve cluster information.
Required
gameIDnumberUnique game ID assigned by Player NetworkRequired

Step 3: Implement web login

After instantiating the accountApi component, call the thirdAuthorize method to request the access token and access secret from Twitter.

accountApi.thirdAuthorize({
third_type: 'twitter',
}).then(
(res) => {
console.log(res);
});

With the Twitter token and secret returned, call the intlAuthorize method to get the Player Network SDK OpenID and token to log in to your website.

accountApi.intlAuthorize({
third_type: 'twitter',
channel_info: {
oauth_token: "EAAI2lTrXAZBwBAC"
oauth_secret: "xxxx"
}
}).then(
(res) => {
console.log(res);
});

Call the intlLogout method to log out from your website.

accountApi.intlLogout({
token: '4567xsdfsd',
openid: 'xxxxxxxx',
channel_id: 9,
}).then(
(res) => {
console.log(res);
});