title: Taro.authorize(option)

sidebar_label: authorize

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.

Reference

Type

  1. (option: Option) => Promise<CallbackResult>

Parameters

Option

Property Type Required Description
scope string Yes The scope to be authorized. For details, see scope list
complete (res: any) => void No The callback function used when the API call completed (always executed whether the call succeeds or fails)
fail (res: any) => void No The callback function for a failed API call
success (res: Result) => void No The callback function for a successful API call

Sample Code

  1. // Use Taro.getSetting to query whether the user has authorized the "scope.record".
  2. Taro.getSetting({
  3. success: function (res) {
  4. if (!res.authSetting['scope.record']) {
  5. Taro.authorize({
  6. scope: 'scope.record',
  7. success: function () {
  8. // The user has allowed the Mini Program to use the recording feature. When the Taro.startRecord API is called later, the pop-up box will not appear.
  9. Taro.startRecord()
  10. }
  11. })
  12. }
  13. }
  14. })

API Support

API WeChat Mini-Program H5 React Native
Taro.authorize ✔️