PHP code example of haistar / tiktokshop-api-client
1. Go to this page and download the library: Download haistar/tiktokshop-api-client library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
haistar / tiktokshop-api-client example snippets
$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);
$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);
$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);