PHP code example of komptip / php-tiktok-sdk

1. Go to this page and download the library: Download komptip/php-tiktok-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

komptip / php-tiktok-sdk example snippets


use Komptip\PhpTiktokSdk\PhpTiktokSdk;
use Komptip\PhpTiktokSdk\AuthorizationScope;
use Komptip\PhpTiktokSdk\UserField;

$tiktok = new PhpTiktokSdk('client_key', 'client_secret');

// Get auth url
$authUrl = $tiktok->createAuthUrl(
    scopes: [AuthorizationScope::UserInfoBasic, AuthorizationScope::UserInfoProfile],
    csrfState: $tiktok->createCsrfState(),
    redirectUri: 'https://example.com/callback'
);

// Get access token
$accessToken = $tiktok->getAccessToken($authorizationCode);

// Get user info
$userInfo = $tiktok->getUserInfo($accessToken['access_token'], [UserField::OpenID, UserField::Displayname]);
bash
composer