Web
本文旨在介绍如何设置 Twitter 身份验证,让您的网页可以使用 Player Network 登录鉴权服务通过 Twitter 渠道登录。
前提条件
1. 在 Twitter 开发者网站上设置游戏
注意
更多关于其他第三方渠道接入 SDK 的信息,请参见 JavaScript SDK。
步骤1:引⼊ JavaScript SDK
目前已支持 npm
包方式和 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>
步骤2:使用 SDK
警告
在集成测试时,将 env
设置为测试环境;项目上线时,将 env
设置为相应的正式环境。
const accountApi = new IntlgameAccountApi({
env: "test", // SDK environment
gameID: 11,
});
参数 | 类型 | 描述 | 备注 |
---|---|---|---|
env | string | SDK 环境 更多信息,请参见 获取部署集群信息。 | 必填 |
gameID | number | Player Network 游戏唯一标识 ID | 必填 |
步骤3:实现网页登录
实例化 accountApi
组件后,调用 thirdAuthorize
接口申请 Twitter 渠道的访问令牌和访问密钥。
accountApi.thirdAuthorize({
third_type: 'twitter',
}).then(
(res) => {
console.log(res);
});
当 Twitter 返回访问令牌和密钥后,调用 intlAuthorize
接口获取 Player Network SDK OpenID 和令牌登录网站。
accountApi.intlAuthorize({
third_type: 'twitter',
channel_info: {
oauth_token: "EAAI2lTrXAZBwBAC"
oauth_secret: "xxxx"
}
}).then(
(res) => {
console.log(res);
});
调用 intlLogout
接口登出网站。
accountApi.intlLogout({
token: '4567xsdfsd',
openid: 'xxxxxxxx',
channel_id: 9,
}).then(
(res) => {
console.log(res);
});