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.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Andrea Olivato
Andrea Olivato

Written by Andrea Olivato

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

No responses yet

Write a response