Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Unicode C) TikTok Shop Get CategoriesSee more TikTok Shop ExamplesAn example showing how to use a TikTok Shops access token in an API call. IMPORTANT: This example requires a pre-release for the next version of Chilkat after the current v9.5.0.99 release. Contact info@chilkatsoft.com if you wish to get a pre-release. However, pre-releases of .NET Core (hosted on NuGet) and Node.js will not be possible.
#include <C_CkHttpW.h> #include <C_CkJsonObjectW.h> #include <C_CkDateTimeW.h> #include <C_CkStringBuilderW.h> #include <C_CkCrypt2W.h> #include <C_CkHttpResponseW.h> void ChilkatSample(void) { HCkHttpW http; HCkJsonObjectW jsonToken; BOOL success; HCkJsonObjectW queryParams; HCkDateTimeW dt; BOOL ascending; BOOL caseSensitive; const wchar_t *appSecret; const wchar_t *path; HCkStringBuilderW sb; int numParams; int i; HCkCrypt2W crypt; const wchar_t *sig; HCkHttpResponseW resp; HCkJsonObjectW json; const wchar_t *id; BOOL is_leaf; const wchar_t *local_name; const wchar_t *parent_id; int j; int count_j; const wchar_t *strVal; int code; const wchar_t *message; const wchar_t *request_id; int count_i; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. http = CkHttpW_Create(); // It is assumed we previously obtained an OAuth2 access token. // This example loads the JSON access token file // saved by this example: Get TikTok Shop OAuth2 Access Token // or refrehsed by this example: Get TikTok Shop Refresh OAuth2 Access Token jsonToken = CkJsonObjectW_Create(); success = CkJsonObjectW_LoadFile(jsonToken,L"qa_data/tokens/tiktok-shops.json"); if (success != TRUE) { wprintf(L"Failed to load tiktok-shops.json\n"); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(jsonToken); return; } // Replace values in all caps with your specific values. // SHOP_CIPHER and SHOP_ID are returned from this example: Get Authorized Shops queryParams = CkJsonObjectW_Create(); CkJsonObjectW_UpdateString(queryParams,L"app_key",L"APP_KEY"); CkJsonObjectW_UpdateString(queryParams,L"shop_cipher",L"SHOP_CIPHER"); CkJsonObjectW_UpdateString(queryParams,L"shop_id",L"SHOP_ID"); dt = CkDateTimeW_Create(); CkJsonObjectW_UpdateString(queryParams,L"timestamp",CkDateTimeW_getAsUnixTimeStr(dt,FALSE)); CkJsonObjectW_UpdateInt(queryParams,L"version",202309); // Sort the JSON members by member name, in ascending order (A-Z), case sensitive.. // Note: The Sort method is added in Chilkat v9.5.0.100 ascending = TRUE; caseSensitive = TRUE; CkJsonObjectW_Sort(queryParams,ascending,caseSensitive); appSecret = L"APP_SECRET"; path = L"/product/202309/categories"; // Build the StringToSign sb = CkStringBuilderW_Create(); CkStringBuilderW_Append(sb,appSecret); CkStringBuilderW_Append(sb,path); numParams = CkJsonObjectW_getSize(queryParams); i = 0; while (i < numParams) { CkStringBuilderW_Append(sb,CkJsonObjectW_nameAt(queryParams,i)); CkStringBuilderW_Append(sb,CkJsonObjectW_stringAt(queryParams,i)); i = i + 1; } CkStringBuilderW_Append(sb,appSecret); crypt = CkCrypt2W_Create(); CkCrypt2W_putHashAlgorithm(crypt,L"SHA256"); CkCrypt2W_putMacAlgorithm(crypt,L"HMAC"); CkCrypt2W_putEncodingMode(crypt,L"hex_lower"); CkCrypt2W_SetMacKeyString(crypt,appSecret); sig = CkCrypt2W_macStringENC(crypt,CkStringBuilderW_getAsString(sb)); CkJsonObjectW_UpdateString(queryParams,L"access_token",CkJsonObjectW_stringOf(jsonToken,L"data.access_token")); CkJsonObjectW_UpdateString(queryParams,L"sign",sig); CkHttpW_SetRequestHeader(http,L"x-tts-access-token",CkJsonObjectW_stringOf(jsonToken,L"data.access_token")); CkHttpW_SetRequestHeader(http,L"content-type",L"application/json"); resp = CkHttpW_QuickRequestParams(http,L"GET",L"https://open-api.tiktokglobalshop.com/product/202309/categories",queryParams); if (CkHttpW_getLastMethodSuccess(http) == FALSE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(jsonToken); CkJsonObjectW_Dispose(queryParams); CkDateTimeW_Dispose(dt); CkStringBuilderW_Dispose(sb); CkCrypt2W_Dispose(crypt); return; } json = CkJsonObjectW_Create(); CkHttpResponseW_GetBodyJson(resp,json); wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp)); CkHttpResponseW_Dispose(resp); code = CkJsonObjectW_IntOf(json,L"code"); message = CkJsonObjectW_stringOf(json,L"message"); request_id = CkJsonObjectW_stringOf(json,L"request_id"); i = 0; count_i = CkJsonObjectW_SizeOfArray(json,L"data.categories"); while (i < count_i) { CkJsonObjectW_putI(json,i); id = CkJsonObjectW_stringOf(json,L"data.categories[i].id"); is_leaf = CkJsonObjectW_BoolOf(json,L"data.categories[i].is_leaf"); local_name = CkJsonObjectW_stringOf(json,L"data.categories[i].local_name"); wprintf(L"local_name: %s\n",local_name); parent_id = CkJsonObjectW_stringOf(json,L"data.categories[i].parent_id"); j = 0; count_j = CkJsonObjectW_SizeOfArray(json,L"data.categories[i].permission_statuses"); while (j < count_j) { CkJsonObjectW_putJ(json,j); strVal = CkJsonObjectW_stringOf(json,L"data.categories[i].permission_statuses[j]"); j = j + 1; } i = i + 1; } CkHttpW_Dispose(http); CkJsonObjectW_Dispose(jsonToken); CkJsonObjectW_Dispose(queryParams); CkDateTimeW_Dispose(dt); CkStringBuilderW_Dispose(sb); CkCrypt2W_Dispose(crypt); CkJsonObjectW_Dispose(json); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.