stallzhan/tiktok-php-sdk-unofficial

PHP login kit implemented according to tiktok document

1.0.0.0 2022-12-15 02:37 UTC

This package is auto-updated.

Last update: 2024-05-15 06:12:37 UTC


README

PHP login kit implemented according to tiktok document

Reference Docs
https://developers.tiktok.com/doc/login-kit-overview/
Login Kit
This is an unofficial SDK for the official Login Kit APIs.
Features
Current features include:
  • Generate TikTok Authorization
  • Obtain tiktok V2 user information
  • Get access token
  • Refresh expired Token
Currently under improvement
Video Kit

Installation

composer require stallzhan/tiktok-php-sdk-unofficial

Basic Example

// include your composer dependencies
require_once 'vendor/autoload.php';

try {
    $client = new \Tiktok\Client();
    $client->setClientKey("xxx");
    $client->setClientSecret("xxx");
    $client->setScopes([
        "user.info.basic",
        "video.upload"
    ]);
    $client->setState("xxx");
    $client->setRedirectUri("xxx");
    $authUrl = $client->createAuthUrl();
    header("Location: $authUrl");
    
    if ($_GET['code']) {
        $data = $client->fetchAccessTokenWithAuthCode($_GET['code']);
        $client->setCredentials($data);
    }
} catch (Exception $e) {
    var_dump($e->getMessage());
}

Apis

Installation

Set credentials

$client->setCredentials($data);

Obtain tiktok V2 user information

$server = new \Tiktok\Service($client);
$userinfo = $server->userinfo_v2->get();

Refresh expired Token

$data = $client->refreshToken();