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
(PowerBuilder) 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.
integer li_rc oleobject loo_Http oleobject loo_JsonToken integer li_Success oleobject loo_QueryParams oleobject loo_Dt integer li_Ascending integer li_CaseSensitive string ls_AppSecret string ls_Path oleobject loo_Sb integer li_NumParams integer i oleobject loo_Crypt string ls_Sig oleobject loo_Resp oleobject loo_Json string ls_Id integer li_Is_leaf string ls_Local_name string ls_Parent_id integer j integer li_Count_j string ls_StrVal integer li_Code string ls_Message string ls_Request_id integer li_Count_i // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. loo_Http = create oleobject // Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0 li_rc = loo_Http.ConnectToNewObject("Chilkat.Http") if li_rc < 0 then destroy loo_Http MessageBox("Error","Connecting to COM object failed") return end if // 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 loo_JsonToken = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_JsonToken.ConnectToNewObject("Chilkat.JsonObject") li_Success = loo_JsonToken.LoadFile("qa_data/tokens/tiktok-shops.json") if li_Success <> 1 then Write-Debug "Failed to load tiktok-shops.json" destroy loo_Http destroy loo_JsonToken return end if // Replace values in all caps with your specific values. // SHOP_CIPHER and SHOP_ID are returned from this example: Get Authorized Shops loo_QueryParams = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_QueryParams.ConnectToNewObject("Chilkat.JsonObject") loo_QueryParams.UpdateString("app_key","APP_KEY") loo_QueryParams.UpdateString("shop_cipher","SHOP_CIPHER") loo_QueryParams.UpdateString("shop_id","SHOP_ID") loo_Dt = create oleobject // Use "Chilkat_9_5_0.CkDateTime" for versions of Chilkat < 10.0.0 li_rc = loo_Dt.ConnectToNewObject("Chilkat.CkDateTime") loo_QueryParams.UpdateString("timestamp",loo_Dt.GetAsUnixTimeStr(0)) loo_QueryParams.UpdateInt("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 li_Ascending = 1 li_CaseSensitive = 1 loo_QueryParams.Sort(li_Ascending,li_CaseSensitive) ls_AppSecret = "APP_SECRET" ls_Path = "/product/202309/categories" // Build the StringToSign loo_Sb = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_Sb.ConnectToNewObject("Chilkat.StringBuilder") loo_Sb.Append(ls_AppSecret) loo_Sb.Append(ls_Path) li_NumParams = loo_QueryParams.Size i = 0 do while i < li_NumParams loo_Sb.Append(loo_QueryParams.NameAt(i)) loo_Sb.Append(loo_QueryParams.StringAt(i)) i = i + 1 loop loo_Sb.Append(ls_AppSecret) loo_Crypt = create oleobject // Use "Chilkat_9_5_0.Crypt2" for versions of Chilkat < 10.0.0 li_rc = loo_Crypt.ConnectToNewObject("Chilkat.Crypt2") loo_Crypt.HashAlgorithm = "SHA256" loo_Crypt.MacAlgorithm = "HMAC" loo_Crypt.EncodingMode = "hex_lower" loo_Crypt.SetMacKeyString(ls_AppSecret) ls_Sig = loo_Crypt.MacStringENC(loo_Sb.GetAsString()) loo_QueryParams.UpdateString("access_token",loo_JsonToken.StringOf("data.access_token")) loo_QueryParams.UpdateString("sign",ls_Sig) loo_Http.SetRequestHeader("x-tts-access-token",loo_JsonToken.StringOf("data.access_token")) loo_Http.SetRequestHeader("content-type","application/json") loo_Resp = loo_Http.QuickRequestParams("GET","https://open-api.tiktokglobalshop.com/product/202309/categories",loo_QueryParams) if loo_Http.LastMethodSuccess = 0 then Write-Debug loo_Http.LastErrorText destroy loo_Http destroy loo_JsonToken destroy loo_QueryParams destroy loo_Dt destroy loo_Sb destroy loo_Crypt return end if loo_Json = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject") loo_Resp.GetBodyJson(loo_Json) Write-Debug string(loo_Resp.StatusCode) destroy loo_Resp li_Code = loo_Json.IntOf("code") ls_Message = loo_Json.StringOf("message") ls_Request_id = loo_Json.StringOf("request_id") i = 0 li_Count_i = loo_Json.SizeOfArray("data.categories") do while i < li_Count_i loo_Json.I = i ls_Id = loo_Json.StringOf("data.categories[i].id") li_Is_leaf = loo_Json.BoolOf("data.categories[i].is_leaf") ls_Local_name = loo_Json.StringOf("data.categories[i].local_name") Write-Debug "local_name: " + ls_Local_name ls_Parent_id = loo_Json.StringOf("data.categories[i].parent_id") j = 0 li_Count_j = loo_Json.SizeOfArray("data.categories[i].permission_statuses") do while j < li_Count_j loo_Json.J = j ls_StrVal = loo_Json.StringOf("data.categories[i].permission_statuses[j]") j = j + 1 loop i = i + 1 loop destroy loo_Http destroy loo_JsonToken destroy loo_QueryParams destroy loo_Dt destroy loo_Sb destroy loo_Crypt destroy loo_Json |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.