ZaloMiniAppSDK
Zalo Mini apps SDK. Contains all methods separated by categories
Table of contents
Authentication Methods
Basics Methods
Data Caching Methods
Device Methods
Navigation Bar Methods
Open APIs Methods
Usage
import apis from 'zmp-sdk;
Authentication Methods
getAccessToken
▸ getAccessToken(): Promise<any>
Get Access Token.
async
function
getAccessToken
example
apis.getAccessToken().then((res) => {
console.log("Success");
}).catch((error) => {
console.log("Fail");
});
Returns: Promise<any>
login
▸ login(): Promise<any>
Login to call more action.
async
function
Login
example
apis.login().then((res) => {
console.log("Success");
}).catch((error) => {
console.log("Fail");
});
Returns: Promise<any>
Basics Methods
getVersion
▸ getVersion(): string
Get the current version of sdk.
Returns: string
Zalo Mini App version.
Data Caching Methods
clearStorage
▸ clearStorage(option
: ClearStorageDataType): Promise<any>
Clears the data cached locally.
async
function
clearStorage
example
apis.clearStorage({
prefix: "prefix" // optional
}).then((res) => {
console.log("Success");
}).catch((error) => {
console.log("Fail");
});
Parameters:
Returns: Promise<any>
getStorage
▸ getStorage(object
: GetStorageDataType): Promise<any>
Asynchronously gets the content of the specified key from the local cache.
async
function
getStorage
example
apis.getStorage({
key: "key",
isPrefix: false
}).then((res) => {
console.log("Success");
}).catch((error) => {
console.log("Fail");
});
Parameters:
Returns: Promise<any>
getStorageInfo
▸ getStorageInfo(): Promise<any>
Asynchronously gets the information related to the current storage.
async
function
getStorageInfo
example
apis.getStorageInfo().then((res) => {
console.log("Success");
}).catch((error) => {
console.log("Fail");
});
Returns: Promise<any>
removeStorage
▸ removeStorage(object
: RemoveStorageDataType): Promise<any>
Removes the specified key from the local cache.
async
function
removeStorage
example
apis.removeStorage({
key: 'key'
}).then((res) => {
console.log("Success");
}).catch((error) => {
console.log("Fail");
});
Parameters:
Returns: Promise<any>
setStorage
▸ setStorage(object
: SetStorageDataType): Promise<any>
Stores data in the specified key in the local cache.
This operation will overwrite the original content of the key.
async
function
setStorage
example
apis.setStorage({
key: "key",
data: "value"
}).then((res) => {
console.log("Success");
}).catch((error) => {
console.log("Fail");
});
Parameters:
Returns: Promise<any>
Device Methods
getNetworkType
▸ getNetworkType(): Promise<NetworkTypeSuccessCallback>
Gets the network type.
async
function
getNetworkType
example
zmpApis.getNetworkType().then((res) => {
console.log(res.networkType);
}).catch((error) => {
console.log("Fail");
});
Returns: Promise<NetworkTypeSuccessCallback>
Promise object
setDeviceOrientation
▸ setDeviceOrientation(object
: DeviceOrientationType): Promise<any>
Sets the color of the navigation bar in the page.
async
function
setDeviceOrientation
example
apis.setDeviceOrientation({
rotate: 0
}).then((res) => {
console.log("Success");
}).catch((error) => {
console.log("Fail");
});
Parameters:
Returns: Promise<any>
Navigation Bar Methods
setNavigationBarColor
▸ setNavigationBarColor(object
: NavBarColorType): Promise<any>
Sets the color of the navigation bar in the page.
async
function
setNavigationBarColor
example
apis.setNavigationBarColor({
color: "#000000"
}).then((res) => {
console.log("Success");
}).catch((error) => {
console.log("Fail");
});
Parameters:
Returns: Promise<any>
setNavigationBarLeftButton
▸ setNavigationBarLeftButton(object
: NavBarLeftMenuType): Promise<any>
Dynamically sets the left button of the current page.
async
function
setNavigationBarLeftButton
example
apis.setNavigationBarLeftButton({
buttonType: 1,
confirmToExit: 1,
dialogMessage: 'Bạn có muốn đóng app này không?'
}).then((res) => {
console.log("Success");
}).catch((error) => {
console.log("Fail");
});
Parameters:
Returns: Promise<any>
setNavigationBarTitle
▸ setNavigationBarTitle(object
: NavBarTitleType): Promise<any>
Dynamically sets the title of the current page.
async
function
setNavigationBarTitle
example
apis.setNavigationBarTitle({
title: "Current Page"
}).then((res) => {
console.log("Success");
}).catch((error) => {
console.log("Fail");
});
Parameters:
Returns: Promise<any>
Open APIs Methods
getUserInfo
▸ getUserInfo(): Promise<any>
Gets user information
async
function
getUserInfo
example
apis.getUserInfo().then((res) => {
console.log("Success");
}).catch((error) => {
console.log("Fail");
});
Returns: Promise<any>