小程序开放平台

文档中心
基础
界面
网络
数据缓存
媒体
位置
开放接口
登录
授权
authorize
设置
发小红书笔记
跳转 AI 能力法务协议
设备
XHSML
性能
文件
数据分析
画布

xhs.authorize

开发
>
JS API
>
开放接口
>
授权
>
authorize
>
更新时间:2024-11-13 19:05:30

以Promise风格调用: 支持

提前向用户发起授权请求

参数

Object object

属性
类型
默认值
必填
说明
scopestring提前向用户发起授权请求
successfunction接口调用成功的回调函数
failfunction接口调用失败的回调函数
completefunction接口调用结束的回调函数(调用成功、失败都会执行)

object.scope 的合法值

说明
scope.userInfo用户信息
scope.userLocation地理位置
scope.userLocationBackground后台定位
scope.writePhotosAlbum保存到相册
scope.camera摄像头

object.success 回调函数

属性
类型
说明
errMsgstring

实例代码

// 可以通过 xhs.getSetting 先查询一下用户是否授权了 "scope.record" 这个 scope
xhs.getSetting({
  success(res) {
    if (!res.authSetting['scope.record']) {
      xhs.authorize({
        scope: 'scope.record',
        success () {
          // 用户已经同意小程序使用录音功能,后续调用 xhs.startRecord 接口不会弹窗询问
          xhs.startRecord()
        }
      })
    }
  }
})