If you're tired of copying the access token every 1 hour, this library is for you
npm install zmp-developer-tokenIf you're tired of copying the access token every 1 hour, this library is for you
``bash`
npm install -D zmp-developer-token
`ts
import { getDeveloperAccessToken } from "zmp-developer-token";
import api from "zmp-sdk";
async function getAccessToken() {
await api.login();
let token = await api.getAccessToken();
if (token === "DEFAULT ACCESS TOKEN") {
token = await getDeveloperAccessToken();
}
return token;
}
`
If you have multiple mini apps inside one domain, specify a unique namespace:
`ts`
await getDeveloperAccessToken("my-app");
You need to provide a valid App ID (which provides the access token), App Secret (to get new tokens) and an initial Refresh Token (which will last many months, and keep renewed automatically until you lost it).
`js`
localStorage.setItem("zdt.appId", "");
localStorage.setItem("zdt.appSecret", "");
localStorage.setItem("zdt.refreshToken", "");
Only execute the above scripts inside Devtools > Console`. Do not put it inside of your source code ☠️
Copyright (c) Zalo Group. and its affiliates. All rights reserved.
The examples provided by Zalo Group are for non-commercial testing and evaluation
purposes only. Zalo Group reserves all rights not expressly granted.