TikTok Scraper in PHP
This package is auto-updated.
Last update: 2021-02-18 18:41:50 UTC
By default, this scraper will attempt to use NodeJS to sign the URL. If you do not have node installed, it will attempt to install it during the composer install step. If you do, it will simply find the path to it. If you'd like to change this logic, you can read more below about setting your signMethod => 'datafetch', an API I have created for signing tiktok urls.
Updates to the
user->account method have been made. No changes in the response object.
This will return video data from the embed endpoint. Right now it's more stable than the normal video route. The only catch is that it does not return
Setting verifyFp manually is now an option, as captcha verification has been taking TikTok by storm. You can set it like so:
$scraper = new Scraper([ 'verifyFp' => 'verify_xxxxx_xxxx_xxxx_xxx...' ])
If you do not set one, by default, the scraper will attempt to generate the following cookies for you:
verifyFp, tt_webid, and tt_webid_v2
However, in most cases at this moment, the fp token will end up being a trigger for captcha.
v1.8.0, the scraper now sets cookies by default, which means that you must provide writable permissions for a
cookies.json file, and then set it in the configuration (see example config below).
Need to disable cookies? Set
'disableCookies' => true in the configuration.
composer require robert-grubb/tiktok-php
require './vendor/autoload.php'; use TikTok\Scraper; // Instantiate TikTok Scraper library $scraper = new Scraper([ // Sign method 'signMethod' => 'datafetch' 'datafetchApiKey' => '' 'userAgent' => '', 'proxy' => [ 'protocol' => 'http', 'address' => '127.0.0.1:8080', 'auth' => 'username:password' ], 'timeout' => 20, // Since v1.8.0 (Must set cookie file) 'cookieFile' => __DIR__ . '/cookies.json' // If not using cookies: 'disableCookies' => true ]);
[ // Sign method 'signMethod' => 'node' // Or datafetch // User agent 'userAgent' => '', // Optional proxy (auth is also optional) 'proxy' => [ 'protocol' => 'http', 'address' => '127.0.0.1:8080', 'auth' => 'username:password' ], // Time before curl request times out 'timeout' => 20 ]
// 30 being the number of results $scraper->user->search('username', 30);
$scraper->user->videos(123415125125); // Or use username, 10 is the count of videos to return. $scraper->user->videos('iratee', 10);
$scraper->user->allVideos(123415125125); // Or use username $scraper->user->allVideos('iratee');
/** * 1st Param: username * 2nd Param: video_id * 3rd Param: watermark (default true) * 4th Param: path to download */ $scraper->user->downloadVideo('username', 123415125125, true, './');
$scraper->discover->get('music'); $scraper->discover->get('user'); $scraper->discover->get('hashtag'); // Offset and count: $scraper->general->discover('music', [ 'count' => 10, 'offset' => 10 ]);
// 25 being the number of items to return. $scraper->trending->videos(25);
// Gets data for music by id $scraper->music->data(12312512512);
// Gets videos for music (25 being the count) $scraper->music->videos(12124124124, 25)
/** * 1st Param: music_id * 2nd Param: path (optional) * 3rd Param: custom name (optional) */ $scraper->music->download(6821468236035541766, './', 'custom-name');
// 30 being the count of videos to return $scraper->hashtag->videos('beatbox', 30);
2 methods of signing the URL is provided.
You can use nodejs, this package will look to see if you have it installed, however, if you do not, it will attempt to install it.
You can use the datafet.ch api that I have personally built to accept requests from anyone to sign a tiktok url. (This package handles it automatically if you set
'signMethod' => 'datafetch'in the configuration.)
DataFetch API does rate limit your requests at a max of 100 requests per 15 minutes. This can be avoided by obtaining an API key, which will then give you access to unlimited requests. You can obtain access by contacting me at
matt [at] grubb [dot] com.
If anything error happens throughout the scraper, it will set the error at the following:
Which will return the following structure:
[ 'error' => true, 'message' => 'Detailed error message here.' ]
Also, the method you called will also return
If there was no error, two things you will notice:
$scraper->erroris set to
- The method you called will not return
This repo and it's contents are in no way affiliated with, authorized, maintained, sponsored or endorsed by TikTok or any of its affiliates or subsidiaries. This is an independent and unofficial package. Use at your own risk.