mobage
概要
在本模块的功能中,含有JavaScript SDK的初始化相关功能。
功能列表
mobage模块中有以下方法。
方法
mobage.init
JS SDK的初始化方法。
此方法在 JS SDK加载完成时,进行SDK的初始化处理。即使不使用JS SDK功能的 NBPF 应用,也必须调用此项。
语法
mobage.init(params ); |
参数
| property | title | type | required | description |
|---|---|---|---|---|
| clientId | Client ID | string | true | 请指定Mobage Developers发行的Client ID。 |
| redirectUri | Redirect URI | string | true | 请指定Mobage Developers设置的RedirectURI。 |
| clientOrigin | Client Origin | string | false | Mobage Developers设置有CDN时,请指定Origin值。 |
| scope | Scope | array | false | 请指定要求验证的数组Scope值。目前可指定的Scope值只有openid和common_api。 |
| responseType | Response type | array | false | 请指定数组的Response type值。目前可指定的Response type值只有token, code, id_token。 |
说明
请从对document对象触发mobageReady事件的事件监听器中,调用mobage.init() 方法。
注意
从 JS SDK 3.1.0 起,当不能写入Local Storage 时,可用mobage.init抛出例外。
用例句所示方法捕获例外,可写入警告或不允许继续游戏等处理。
例
典型的初始化代码如下所示。
document. addEventListener (" mobageReady ", function(evt) {
try {
mobage.init ({
clientId: "12000129-4" ,
redirectUri : "https://sandbox.example.com/login_cb",
clientOrigin : "`http://example.sb-cdn.pf.mobage.jp",`
scope: ["openid", "common_api"],
responseType : ["code", "token", "id_token"]
});
}catch (e){
if (e.message === 'This browser can not use LocalStorage') {
alert("此浏览器可能有Safari Private Mode。请解除Private模式后再执行。");
}
}
}, false );