@tiktok-service/app-center-connect
TypeScript icon, indicating that this package has built-in type declarations

0.3.0 • Public • Published

TikTok App Connect Library

Introduction


TikTok App Connect library provides a simple way for the app center apps to communicate with TikTok app center page. It currently supports functions including:

  • Get session token (getSessionToken)
  • Redirect users to API authorization page (redirectToAuth)
  • Allow users to request redirection to any pages (requestRedirectionTo)

How to install


npm i @tiktok-service/app-center-connect

How to Use


Below is the sample code for how to use the methods provided in the package.

import ACApp, { ERROR_MSG } from '@tiktok-service/app-center-connect';

console.log(ERROR_MSG);
// The list of possible error messages for each function call was exported as `ERROR_MSG`
/*
{
    getSessionToken: {
        failed: "failed to get session token. please try again later",
        timeout: "request timeout"
    },
    redirectToAuth: {
        unsupported:
            "Unsupported auth type. Please select from: MAPI, TTAAPI and CMAPI"
    },
}
*/

const app = new ACApp('your_app_id');

// <!-- Get Session Token -->
try {
  const sessionToken = await app.getSessionToken();
} catch (e) {
  if (e.message === ERROR_MSG.getSessionToken.timeout) {
    // handle timeout error
  }
  // <!-- ... -->
}

// <!-- Redirect to TikTok Accounts API/Creator Marketplace API Auth Page -->
// <!-- Supported auth type: MAPI - Marketing API -->
// <!-- Supported auth type: TTAAPI - TikTok Accounts API -->
// <!-- Supported auth type: CMAPI - Creator Marketplace API -->
app.redirectToAuth('TTAAPI' / 'CMAPI');

try {
  const isRedirectionSuccessful = await app.requestRedirectionTo(
    'https://example.com/'
  );
  console.log(isRedirectionSuccessful);
} catch (e) {
  if (e.message === ERROR_MSG.requestRedirectionTo.notAllowed) {
    // handle URL not allowed error
  }
}

// <!-- Get App Center Page URL -->
pageURL = app.getAppCenterURL();

Readme

Keywords

none

Package Sidebar

Install

npm i @tiktok-service/app-center-connect

Weekly Downloads

2,190

Version

0.3.0

License

ISC

Unpacked Size

9.91 kB

Total Files

4

Last publish

Collaborators

  • tiktok-service