TikTok PHP SDK updated with Publish capabilities (Direct Post upload)

Andrea Olivato
1 min readDec 29, 2023

The unofficial TikTok PHP SDK which I maintain together with the Lnk.Bio developers has been updated with the new Direct Post capabilities of the TikTok official APIS.

The API reference from TikTok can be found here.

The updated version is the 0.6 and it’s already available both on GitHub and Composer.

The main purpose of this release is to allow users to publish on TikTok directly via API using the Direct Post function. In the library, this is achieved with 3 new classes:

  • VideoFromUrl
  • VideoFromFile
  • ImagesFromUrls

The syntax to perform an upload is something like

$video = new VideoFromUrl($post->getVideo(), $post->getCaption(), self::PRIVACY_PUBLIC);
$publishInfo = $video->publishReplacingInvalidValues($this);
if (!$publishInfo->isSuccess()) {
echo "Impossible to publish: ".$publishInfo->getErrorCode().": ".$publishInfo->getErrorMessage();
}
$publishStatus = $this->waitUntilPublished($publishInfo->getPublishID(), 30);
if ($PublishStatus->getStatus() == PublishStatus::PUBLISH_COMPLETE) {
echo "UPLOADED".PHP_EOL;
} else {
echo "ERROR".PHP_EOL;
echo $PublishStatus->getErrorCode().": ".$PublishStatus->getErrorMessage().PHP_EOL;
}

The SDK also automatically checks for the creator’s entitlements: e.g. if the creator cannot publish Public videos, the class will throw an exception, the same for all the other parameters (comments turned off, no stitch, etc)

The new release comes with a bit of rewriting of existing data structure, so watch out when upgrading.

--

--

Andrea Olivato

Co-founder @Lnk.Bio — Developing stuff on the Web since 2003