# wx.authorize(Object object)

Start from base library version 1.2.0. Please remaining backward compatible.

Initiates an authorization request to the user in advance. After this API is called, a pop-up box appears to ask whether the user agrees to authorize the Mini Program to use a specific feature or obtain certain data of the user, but the appropriate APIs are not actually called. If the user has already given the authorization, the pop-up box will not appear, and a message indicating success is returned directly. For more usages, see User Authorization.

# Parameters

# Object object

Attribute Type Default Required Description
scope string Yes The scope to be authorized. For details, see scope list.
success function No The callback function for a successful API call
fail function No Callback function for failed API call
complete function No Callback function used when API call completed (always executed whether call succeeds or fails)

# Sample Code

// Use wx.getSetting to query whether the user has authorized the "scope.record".
wx.getSetting({
  success(res) {
    if (!res.authSetting['scope.record']) {
      wx.authorize({
        scope: 'scope.record',
        success () {
          // The user has allowed the Mini Program to use the recording feature. When the wx.startRecord API is called later, the pop-up box will not appear.
          wx.startRecord()
        }
      })
    }
  }
})
点击咨询小助手