PHP code example of ssovit / tiktok-api

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

    

ssovit / tiktok-api example snippets


$api=new \Sovit\TikTok\Api(array(/* config array*/));

$trendingFeed=$api->getTrendingFeed($maxCursor=0);

$userData=$api->getUser("tiktok");

$userFeed=$api->getUserFeed("tiktok",$maxCursor=0);

$challenge=$api->getChallenge("foryourpage");

$challengeFeed=$api->getChallengeFeed("foryourpage",$maxCursor=0);

$musc=$api->getMusic("6798898508385585925");

$musicFeed=$api->getMusicFeed("6798898508385585925",$maxCursor=0);

$videoData=$api->getVideoByID("6829540826570296577");

$videoData=$api->getVideoByUrl("https://www.tiktok.com/@zachking/video/6829303572832750853");

$noWatermark=$api->getNoWatermark("https://www.tiktok.com/@zachking/video/6829303572832750853");


$api=new \Sovit\TikTok\Api(array(
	"user-agent"		=> 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36', // Valid desktop browser HTTP User Agent
	"proxy-host"		=> false,
	"proxy-port"		=> false,
	"proxy-username"	=> false,
	"proxy-password"	=> false,
	"cache-timeout"		=> 3600 // 1 hours cache timeout
	"cookie_file"		=> sys_get_temp_dir() . 'tiktok.txt', // cookie file path
	"nwm_endpoint"		=> "https://my-api.example.com" // private api endpoint
	"api_key"		=> "API_KEY" // see below on how to get API key
	), $cache_engine=false);

// Example using WordPress transient as cache engine
Class MyCacheEngine{
	function get($cache_key){
		return get_transient($cache_key);
	}
	function set($cache_key,$data,$timeout=3600){
		return set_transient($cache_key,$data,$timeout);
	}
}


$cache_engine=new MyCacheEngine();
$api=new \Sovit\TikTok\Api(array(/* config array*/),$cache_engine);