PHP code example of swuppio / tiktok-wrapper

1. Go to this page and download the library: Download swuppio/tiktok-wrapper 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/ */

    

swuppio / tiktok-wrapper example snippets


$wrp = new TikTokWrapper();

$authDto = $wrp
    ->getAuthApi('CLIENT_KEY', 'CLIENT_SECRET')
    ->fetchAccessToken('CODE', 'http://site.com/redirect_uri');

$displayApi = $wrp->getDisplayApi($authDto->accessToken);

$userInfoDto = $displayApi
    ->getUserInfo()
    ->setFields(
        UserInfoContract::Username->value,
        // ...
    )
    ->get();

echo $userInfoDto->username;

$wrp = new TikTokWrapper();

$authDto = $wrp
    ->getAuthApi('CLIENT_KEY', 'CLIENT_SECRET')
    ->refreshAccessToken('REFRESH_TOKEN');

echo $authDto->accessToken;

# code...

$displayApi = $wrp->getDisplayApi('ACCESS_TOKEN');

$queryVideosArr = $displayApi
    ->getQueryVideos()
    ->setFields(
        VideoContract::EmbedHtml->value,
        // ...
    )
    ->setVideoIds([
        '7251141220062350593',
        // ...
    ])
    ->get();

foreach ($queryVideosArr->videos as $video) {
    echo $video->embedHtml;
}