swan.getLoginCode

基础库 3.230.1 版本开始支持。

解释:获取宿主 App 登录凭证(Authorization Code)。

方法参数

Object object

返回参数说明

属性名类型必填默认值说明
timeoutNumber超时时间(单位:ms)
successFunction接口调用成功的回调函数
failFunction接口调用失败的回调函数
completeFunction接口调用结束的回调函数(调用成功、失败都会执行)

success 返回参数说明

参数类型说明
codeString用户登录凭证(有效期十分钟),开发者需要在开发者服务器后台调用 api,使用 code 换取 session_key 等信息。
用户登录凭证 code 只能使用一次。

代码示例

  • SWAN
  • JS
  1. <view class="wrap">
  2. <button type="primary" bindtap="getLoginCode">获取用户登录百度 APP 凭证</button>
  3. </view>
  1. Page({
  2. getLoginCode() {
  3. swan.getLoginCode({
  4. success: res => {
  5. console.log('getLoginCode success', res);
  6. },
  7. fail: err => {
  8. console.log('getLoginCode fail', err);
  9. }
  10. });
  11. }
  12. });