Docs
Login
login(cb,opts)
Calling TTMinis.login prompts the user to authenticate your application using the Login Dialog.
Calling TTMinis.login results in TikTok Minis SDK attempting to open a popup window. As such, this method should only be called after a user click event, otherwise the popup window will be blocked by most browsers.
Parameters
/**
* Prompts a user to login to your app using the Login dialog in a popup
* @param {loginCallback} cb - callback function, see params below
* @param {Object} opts - optional params
* @param {string} opts.scope - permission scopes splitted by ','
* @param {boolean} opts.returnScopes - whether return list of already authorized scopes
*/
TTMinis.login(cb, opts);Callback response
{
authResponse: {
code:'...', // auth code
grantedScopes:'...' // List of authorized scopes splitted by ',', exist only when opts.returnScopes is true
}
}Example
TTMinis.login(function(response){
if (response.authResponse?.code) {
// The user has logged in and authorized the application
// You can get the code and send it to the backend in exchange for open_id, access_token, etc
let code = response.authResponse.code;
} else {
// Other errors or deauthorization response.authResponse is null
}
}, {
});Permissions
By default, calling TTMinis.login will attempt to authenticate the user with only the basic permissions (avatar, displayname, openid and unionid). If you want one or more additional permissions, call TTMinis.login with an option object, and set the scope parameter with a comma-separated list of the permissions you wish to request from the user.
- For account binding, please apply for the scope user.info.basic on TikTok Developer Portal - Login Kit.
- When you call
TTMinis.login, please refer to the example as follows:
TTMinis.login(function(response) {
// handle the response
}, {scope: 'user.info.basic,user.info.phone'});By setting the returnScopes option to true in the option object when calling TTMinis.login, you will receive a list of the granted permissions in the grantedScopes field on the authResponse object.
TTMinis.login(function(response) {
// handle the response
}, {
scope: 'user.info.basic,user.info.phone',
returnScopes: true
});If you need to collect more permissions from users who have already authenticated with your application, call TTMinis.login again with the permissions you want the user to grant. In the authentication dialog, the user will only ever be asked for permissions they have not already granted.
getLoginStatus(cb,opts)
TTMinis.getLoginStatusallows you to determine if a user has authenticated your app. There are three possible states:
connected: The user has logged in and authorized the application.not_authorized: The user has logged in but has not been authorized.unknown: The user is not logged into TikTok, or explicitly not authorized.
Parameters
/**
* Prompts to check whether a user has authenticated your app
* @param {getLoginStatusCallback,opts} cb - callback function, see params below
*/
TTMinis.getLoginStatus(callback,opts);Callback response
{
/**
* 'connected': The user has completed the login and auth process
* 'not_authorized': The user has completed the login but not auth process
* 'unknown': The user hasn't completed login or auth process
*/
status: 'connected',
}Example
TTMinis.getLoginStatus(function(response) {
if (response.status === 'connected') {
// The user has completed the login and auth process
} else if (response.status === 'not_authorized') {
// The user has completed the login but not auth process
} else { // response.status == ‘unknown’
// The user hasn't completed login or auth process
},
{
clientKey: '',
scope: ""
}
);