swan.getLoginCode
基础库 3.230.1 版本开始支持。
解释:获取宿主 App 登录凭证(Authorization Code)。
方法参数
Object object
返回参数说明
属性名 | 类型 | 必填 | 默认值 | 说明 |
---|---|---|---|---|
timeout | Number | 否 | 超时时间(单位:ms) | |
success | Function | 否 | 接口调用成功的回调函数 | |
fail | Function | 否 | 接口调用失败的回调函数 | |
complete | Function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
success 返回参数说明
参数 | 类型 | 说明 |
---|---|---|
code | String | 用户登录凭证(有效期十分钟),开发者需要在开发者服务器后台调用 api,使用 code 换取 session_key 等信息。 用户登录凭证 code 只能使用一次。 |
代码示例
- SWAN
- JS
<view class="wrap">
<button type="primary" bindtap="getLoginCode">获取用户登录百度 APP 凭证</button>
</view>
Page({
getLoginCode() {
swan.getLoginCode({
success: res => {
console.log('getLoginCode success', res);
},
fail: err => {
console.log('getLoginCode fail', err);
}
});
}
});