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
(PureBasic) 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.
IncludeFile "CkJsonObject.pb" IncludeFile "CkDateTime.pb" IncludeFile "CkHttp.pb" IncludeFile "CkCrypt2.pb" IncludeFile "CkStringBuilder.pb" IncludeFile "CkHttpResponse.pb" Procedure ChilkatExample() ; This example assumes the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. http.i = CkHttp::ckCreate() If http.i = 0 Debug "Failed to create object." ProcedureReturn EndIf ; 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.i = CkJsonObject::ckCreate() If jsonToken.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success.i = CkJsonObject::ckLoadFile(jsonToken,"qa_data/tokens/tiktok-shops.json") If success <> 1 Debug "Failed to load tiktok-shops.json" CkHttp::ckDispose(http) CkJsonObject::ckDispose(jsonToken) ProcedureReturn EndIf ; Replace values in all caps with your specific values. ; SHOP_CIPHER and SHOP_ID are returned from this example: Get Authorized Shops queryParams.i = CkJsonObject::ckCreate() If queryParams.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckUpdateString(queryParams,"app_key","APP_KEY") CkJsonObject::ckUpdateString(queryParams,"shop_cipher","SHOP_CIPHER") CkJsonObject::ckUpdateString(queryParams,"shop_id","SHOP_ID") dt.i = CkDateTime::ckCreate() If dt.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckUpdateString(queryParams,"timestamp",CkDateTime::ckGetAsUnixTimeStr(dt,0)) CkJsonObject::ckUpdateInt(queryParams,"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.i = 1 caseSensitive.i = 1 CkJsonObject::ckSort(queryParams,ascending,caseSensitive) appSecret.s = "APP_SECRET" path.s = "/product/202309/categories" ; Build the StringToSign sb.i = CkStringBuilder::ckCreate() If sb.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkStringBuilder::ckAppend(sb,appSecret) CkStringBuilder::ckAppend(sb,path) numParams.i = CkJsonObject::ckSize(queryParams) i.i = 0 While i < numParams CkStringBuilder::ckAppend(sb,CkJsonObject::ckNameAt(queryParams,i)) CkStringBuilder::ckAppend(sb,CkJsonObject::ckStringAt(queryParams,i)) i = i + 1 Wend CkStringBuilder::ckAppend(sb,appSecret) crypt.i = CkCrypt2::ckCreate() If crypt.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkCrypt2::setCkHashAlgorithm(crypt, "SHA256") CkCrypt2::setCkMacAlgorithm(crypt, "HMAC") CkCrypt2::setCkEncodingMode(crypt, "hex_lower") CkCrypt2::ckSetMacKeyString(crypt,appSecret) sig.s = CkCrypt2::ckMacStringENC(crypt,CkStringBuilder::ckGetAsString(sb)) CkJsonObject::ckUpdateString(queryParams,"access_token",CkJsonObject::ckStringOf(jsonToken,"data.access_token")) CkJsonObject::ckUpdateString(queryParams,"sign",sig) CkHttp::ckSetRequestHeader(http,"x-tts-access-token",CkJsonObject::ckStringOf(jsonToken,"data.access_token")) CkHttp::ckSetRequestHeader(http,"content-type","application/json") resp.i = CkHttp::ckQuickRequestParams(http,"GET","https://open-api.tiktokglobalshop.com/product/202309/categories",queryParams) If CkHttp::ckLastMethodSuccess(http) = 0 Debug CkHttp::ckLastErrorText(http) CkHttp::ckDispose(http) CkJsonObject::ckDispose(jsonToken) CkJsonObject::ckDispose(queryParams) CkDateTime::ckDispose(dt) CkStringBuilder::ckDispose(sb) CkCrypt2::ckDispose(crypt) ProcedureReturn EndIf json.i = CkJsonObject::ckCreate() If json.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkHttpResponse::ckGetBodyJson(resp,json) Debug Str(CkHttpResponse::ckStatusCode(resp)) CkHttpResponse::ckDispose(resp) id.s is_leaf.i local_name.s parent_id.s j.i count_j.i strVal.s code.i = CkJsonObject::ckIntOf(json,"code") message.s = CkJsonObject::ckStringOf(json,"message") request_id.s = CkJsonObject::ckStringOf(json,"request_id") i = 0 count_i.i = CkJsonObject::ckSizeOfArray(json,"data.categories") While i < count_i CkJsonObject::setCkI(json, i) id = CkJsonObject::ckStringOf(json,"data.categories[i].id") is_leaf = CkJsonObject::ckBoolOf(json,"data.categories[i].is_leaf") local_name = CkJsonObject::ckStringOf(json,"data.categories[i].local_name") Debug "local_name: " + local_name parent_id = CkJsonObject::ckStringOf(json,"data.categories[i].parent_id") j = 0 count_j = CkJsonObject::ckSizeOfArray(json,"data.categories[i].permission_statuses") While j < count_j CkJsonObject::setCkJ(json, j) strVal = CkJsonObject::ckStringOf(json,"data.categories[i].permission_statuses[j]") j = j + 1 Wend i = i + 1 Wend CkHttp::ckDispose(http) CkJsonObject::ckDispose(jsonToken) CkJsonObject::ckDispose(queryParams) CkDateTime::ckDispose(dt) CkStringBuilder::ckDispose(sb) CkCrypt2::ckDispose(crypt) CkJsonObject::ckDispose(json) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.