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 Authorized ShopsSee more TikTok Shop ExamplesAn example showing how to get the authorized shops in the TikTok Shops API. 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. For more information, see https://partner.tiktokshop.com/docv2/page/6507ead7b99d5302be949ba9?external_id=6507ead7b99d5302be949ba9
#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 *cipher; const wchar_t *code_str; const wchar_t *id; const wchar_t *name; const wchar_t *region; const wchar_t *seller_type; 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; } queryParams = CkJsonObjectW_Create(); CkJsonObjectW_UpdateString(queryParams,L"app_key",L"APP_KEY"); 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"/authorization/202309/shops"; // 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/authorization/202309/shops",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)); wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp)); CkHttpResponseW_Dispose(resp); // Sample JSON response... // Use this online tool to generate parsing code from sample JSON: // Generate Parsing Code from JSON // { // "code": 0, // "data": { // "shops": [ // { // "cipher": "GCP_XF90igAAAABh00qsWgtvOiGFNqyubMt3", // "code": "CNGBCBA4LLU8", // "id": "7000714532876273420", // "name": "Maomao beauty shop", // "region": "GB", // "seller_type": "CROSS_BORDER" // } // ] // }, // "message": "Success", // "request_id": "202203070749000101890810281E8C70B7" // } 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.shops"); while (i < count_i) { CkJsonObjectW_putI(json,i); cipher = CkJsonObjectW_stringOf(json,L"data.shops[i].cipher"); code_str = CkJsonObjectW_stringOf(json,L"data.shops[i].code"); id = CkJsonObjectW_stringOf(json,L"data.shops[i].id"); name = CkJsonObjectW_stringOf(json,L"data.shops[i].name"); region = CkJsonObjectW_stringOf(json,L"data.shops[i].region"); seller_type = CkJsonObjectW_stringOf(json,L"data.shops[i].seller_type"); 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.