@uni/share
v1.0.1
Published
[![npm](https://img.shields.io/npm/v/@uni/authorize.svg)](https://www.npmjs.com/package/@uni/authorize)
Downloads
1
Readme
authorize
Some of the APIs need users’ authorization before they can be called. We have divided these APIs into multiple scope according to the scope of usage. The users can select scope to authorize. After a scope is authorized, all of its APIs can be used directly.
When such an API is called:
- If the user has not accepted or rejected this authorization, a pop-up window will appear to ask the user if he/she wants to accept. The API can be called only after the user clicks to accept;
- If the user has accepted authorization, the API can be called directly;
- If the user has rejected authorization, no pop-up appears. Instead, API fail callback will be accessed directly. Developers should make the scenario compatible where the user has rejected to authorization.
Supported
Install
$ npm install @uni/authorize --save
or
$ npm install @uni/apis --save
Usage
import authorize from '@uni/authorize';
authorize({
scope: 'scope.userLocation',
success: () => {
console.log('success');
},
fail: (res) => {
console.log('fail', res);
},
complete: (res) => {
console.log('complete', res);
}
});
authorize({
scope: 'scope.userLocation',
}).then((res?) => {
console.log('success');
});
你也可以从大包引入:
import { authorize } from '@uni/apis';
Parameters
| Property | Type | Description | Required | Default |
| --- | --- | --- | --- | --- |
| options | object
| | 是 | - |
| options.scope | string
| The scope to be authorized. For details, see scope list | Yes | - |
| options.success | Function
| The callback function for a successful API call | No | - |
| options.fail | Function
| The callback function for a failed API call | No | - |
| options.complete | Function
| The callback function used when the API call completed (always executed whether the call succeeds or fails) | No | - |
Scope List
| scope | Description | Corresponding APIs | Supported | | ------ | -------- | ------ | ---- | | scope.userInfo | User information | getUserInfo, getOpenUserInfo | <img alt="kuaiShouMiniProgram" src="https://gw.alicdn.com/imgextra/i4/O1CN01kzmJMM24jcFEzp5Wv_!!6000000007427-2-tps-200-200.png" width="25px" height="25px" title="快手小程序" | | scope.userLocation | Geographic location | getLocation, chooseLocation | <img alt="kuaiShouMiniProgram" src="https://gw.alicdn.com/imgextra/i4/O1CN01kzmJMM24jcFEzp5Wv_!!6000000007427-2-tps-200-200.png" width="25px" height="25px" title="快手小程序" | | scope.userLocationBackground | Background positioning | startLocationUpdateBackground | <img alt="kuaiShouMiniProgram" src="https://gw.alicdn.com/imgextra/i4/O1CN01kzmJMM24jcFEzp5Wv_!!6000000007427-2-tps-200-200.png" width="25px" height="25px" title="快手小程序" | | scope.werun | WeRun step counts | getWeRunData | | | scope.record | Recording feature | startRecord | <img alt="kuaiShouMiniProgram" src="https://gw.alicdn.com/imgextra/i4/O1CN01kzmJMM24jcFEzp5Wv_!!6000000007427-2-tps-200-200.png" width="25px" height="25px" title="快手小程序" | | scope.writePhotosAlbum | Saves to album | saveImage, saveVideo | <img alt="kuaiShouMiniProgram" src="https://gw.alicdn.com/imgextra/i4/O1CN01kzmJMM24jcFEzp5Wv_!!6000000007427-2-tps-200-200.png" width="25px" height="25px" title="快手小程序" | | scope.camera | Camera | scanCode,chooseImage,chooseVideo | <img alt="kuaiShouMiniProgram" src="https://gw.alicdn.com/imgextra/i4/O1CN01kzmJMM24jcFEzp5Wv_!!6000000007427-2-tps-200-200.png" width="25px" height="25px" title="快手小程序" | | scope.calendar | calendar | addEventOnCalendar,deleteEventOnCalendar | | | auth_base | Silent authorization will not initiate authorization floating window. Get auth_ from Alipay client Code, the incoming server invokes the alipay.system.oauth.token interface to get Alipay membership identifier (user_). id)| addEventOnCalendar,deleteEventOnCalendar | | | auth_zhima | User sesame information | zhima.credit.score.brief.get | |
Response<Response>
(Not general)
Note: only Alipay applet returns.
| Property | Type | Description |
| --- | --- | --- |
| response | object
| - |
| response.authCode | string
| Authorization code |
| response.authErrorScopes | object
| Failed authorization type. Key is the scope of failed authorization, and value is the corresponding error code |
| response.authSuccessScopes | Array
| Successful authorization scope |
hideShareMenu
Hides the Forward button on the current page
Supported
Install
$ npm install @uni/share --save
or
$ npm install @uni/apis --save
Usage
import { hideShareMenu } from '@uni/share';
hideShareMenu();
你也可以从大包引入:
import { share } from '@uni/apis';
Parameters
| Property | Type | Description | Required | Default | Supported |
| --- | --- | --- | --- | --- | --- |
| options | object
| | No | - | - | |
| options.menus | Array.<string>
| This interface is a Beta version and is only supported on the Android platform for the time being. The list of forward button names that need to be displayed, the default is ['shareAppMessage']. The legal values of the button name include "shareAppMessage" and "shareTimeline" | No | - | |
| options.success | Function
| The callback function for a successful API call | No | - | |
| options.fail | Function
| The callback function for a failed API call | No | - | |
| options.complete | Function
| The callback function used when the API call completed (always executed whether the call succeeds or fails) | No | - | |