Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat small program user information and authorization


May 18, 2021 WeChat Mini Program Development Document


Table of contents


Authorized

Some interfaces require user authorization consent before they can be invoked. We divide these interfaces into scopes by scope of use, and the user chooses to authorize scope, and when granted to a scope, all of its corresponding interfaces can be used directly.

When such interfaces are called:

  • If the user does not accept or reject this permission, the window will ask the user, the user click to agree before calling the interface;
  • If the user is authorized, the interface can be called directly;
  • If the user has denied authorization, there is no bounce window, but instead directly into the interface fail callback. Ask the developer to be compatible with scenarios in which the user refuses authorization.

Get user authorization settings

Developers can use wx.getSetting to obtain the user's current authorization status.

Open the settings interface

The user can control the authorization status of the small program in the small program settings interface ("top right corner" - "About" - "top right corner" - "Settings").

Developers can call wx.openSetting to open the settings interface and direct the user to open the authorization.

Start an authorization request in advance

Developers can use wx.authorize to initiate authorization requests to users in advance before calling the authorization API.

Scope list

scope The corresponding interface Describe
scope.userInfo wx.getUserInfo User information
scope.userLocation wx.getLocation, wx.chooseLocation Location
scope.userLocationBackground wx.startLocationUpdateBackground Background positioning
scope.address wx.chooseAddress mailing address
scope.invoiceTitle wx.chooseInvoiceTitle Invoice
scope.invoice wx.chooseInvoice Get invoices
scope.werun wx.getWeRunData WeChat sports step
scope.record wx.startRecord recording function
scope.writePhotosAlbum wx.saveImageToPhotosAlbum, wx.saveVideoToPhotosAlbum save into the album
scope.camera Camera components Camera

Authorized validity period

Once a user explicitly consents or rejects authorization, its authorization relationship is recorded in the background until the user actively deletes the small program.

Best practices

When you really need to use the authorization interface, you initiate an authorization request to the user and state the reasons for using the feature clearly in the authorization request.

Precautions

  1. wx.scope: "scope.userInfo"), no authorization window will pop up, please use the "getUserInfo"/"""""""""""""""""""
  2. Geo-location descriptions must be configured when you need to authorize scope.userLocation, scope.userLocationBackground.

Background positioning

Unlike other types of authorizations, scope.userLocationBackground does not play a window to alert the user. T he user is required to proactively set the Location Information option to "During and after using a small program" on the settings page. Developers can open the settings page by calling wx.openSetting.

WeChat small program user information and authorization