haistar / tiktokshop-api-client
There is no license information available for the latest version (v3.0.0) of this package.
Unofficial Tiktok Shop API Client build in PHP
v3.0.0
2023-01-17 14:53 UTC
Requires
- guzzlehttp/guzzle: ^7.0
Requires (Dev)
- phpunit/phpunit: ^7
- vlucas/phpdotenv: ^5.3
This package is auto-updated.
Last update: 2024-10-17 18:51:12 UTC
README
How To Install
composer require haistar/tiktokshop-api-client
Generate Authorization URL
$authUrl = TiktokShopAuthResource::generateAuthUrl($_ENV["AUTH_URL"], $_ENV["APP_KEY"]);
Get Access Token
$tiktokShopConfig = new TiktokShopConfig();
$tiktokShopConfig->setAppKey($_ENV["APP_KEY"]);
$tiktokShopConfig->setSecretKey($_ENV["APP_SECRET"]);
$tiktokAuthResource = new TiktokShopAuthResource();
$baseUrl = $_ENV["AUTH_URL"];
$apiAccessToken = "/api/v2/token/get";
$params = [
"auth_code" => $_ENV["AUTH_CODE"],
"grant_type" => "authorized_code",
];
$response = $tiktokAuthResource->httpCallGet($baseUrl, $apiAccessToken, $params, $tiktokShopConfig);
$this->assertEquals("0", $response->code);
$this->assertEquals("success", $response->success);
Renew Refresh Token
$tiktokShopConfig = new TiktokShopConfig();
$tiktokShopConfig->setAppKey($_ENV["APP_KEY"]);
$tiktokShopConfig->setSecretKey($_ENV["APP_SECRET"]);
$tiktokAuthResource = new TiktokShopAuthResource();
$baseUrl = $_ENV["AUTH_URL"];
$apiRenewRefreshToken = "/api/v2/token/refresh";
$params = [
"refresh_token" => $_ENV["REFRESH_TOKEN"],
"grant_type" => "refresh_token",
];
$response = $tiktokAuthResource->httpCallGet($baseUrl, $apiRenewRefreshToken, $params, $tiktokShopConfig);
$this->assertEquals("0", $response->code);
$this->assertEquals("success", $response->success);
TiktokShop Global API
$tiktokShopConfig = new TiktokShopConfig();
$tiktokShopConfig->setAppKey($_ENV["APP_KEY"]);
$tiktokShopConfig->setSecretKey($_ENV["APP_SECRET"]);
$tiktokShopConfig->setAccessToken($_ENV["ACCESS_TOKEN"]);
$tiktokGeneralResource = new TiktokShopGeneralResource();
$baseUrl = $_ENV["SERVER_URL"];
$apiAuthorizedShop = "/api/shop/get_authorized_shop";
$response = $tiktokGeneralResource->httpCallGet($baseUrl, $apiAuthorizedShop, [], $tiktokShopConfig);
$this->assertEquals(0, $response->code);
$this->assertEquals($_ENV["SELLER_NAME"], $response->data->shop_list[0]->shop_name);