All Products
Search
Document Center

SuperApp:wv.authorize

Last Updated:Aug 14, 2025

Before the current miniapp calls device-related JavaScript APIs (refer to the following scope list for corresponding interfaces), it needs to request authorization from the user in advance. When the API is called, a pop-up window will immediately ask the user whether they agree to authorize the miniapp to use a certain function or obtain some of the user's data, but the corresponding JavaScript API will not actually be called. If the user has already agreed to the authorization previously, a pop-up will not display, and the call will return success immediately.

Request parameters

Parameter

Type

Required

Description

scope

String

Yes

The user device authorization scope that you want to obtain.

success

Function

No

The callback functions for successful authorization.

fail

Function

No

The callback functions for failed authorization.

scope

scope

Description

corresponding interface

location

The geographical location

WVLocation.getLocation;WVLocation.searchLocation

camera

The camera

WVScan.scan

bluetooth

The bluetooth

WVBluetooth all methods

album

The album

WVVideo.chooseVideo;WVCamera.takePhoto

contacts

The contacts

WVContacts all methods

microphone

The microphone

WVMotion.listenBlow;

WVMotion.stopListenBlow

file

The file

WVFile all methods 

WVVideo.saveVideoToPhotosAlbum;

WVImage.saveImage

call

The call

WVCall.dial;WVCall.call

vibrate

The vibrate

WVMotion.vibrate

screen

the screen

WVScreenCapture.capture

Response parameters

The callback functions for successful calls receive an object. The following table describes the attributes of the object.

Attribute

Type

Description

successScope

JSONObject

The user device authorization scope that are granted to the miniapp.

msg

String

The error messages

The callback functions for failed calls receive an object. The following table describes the error messages, error descriptions and corresponding solutions in the object.

Error message

Error Description

Solution

You need to configure the authorization switch to apply for authorization

Need to turn on the authorization switch

Check whether the authorization switch is opened

Parameter parsing exception

Data parsing exception

Check the data format.

Authorization scope cannot be empty

The scope is null

Check the scope.

User not bound

Container need registration userid

Check the container registration user information.

User refuses authorization request

User denied authorization

You can explain the purpose of the function in detail to obtain authorization.

The authorization you requested does not exist. Please check the parameters

The scope is not within the scope

The scope contains an invalid value. Please check the scope parameter.

Sample code

window.WindVane.call('wv', 'getSetting', {}, function(res) {
    if (!res.authSetting['location']) {
      	window.WindVane.call('wv', 'authorize', {scope: 'location'}, function(res) {
          	if (res.successScope['location']) {
              	alert('success authorize location');
              	//call the jsapi you need to use
            }
        }, function(e) {
          	alert('failure:' + JSON.stringify(e));
        })
    } else {
      	alert('success authorize location');
    }
}, function(e) {
    alert('failure:' + JSON.stringify(e));
});