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 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
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 queryParams.i = CkJsonObject::ckCreate() If queryParams.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckUpdateString(queryParams,"app_key","APP_KEY") 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 = "/authorization/202309/shops" ; 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/authorization/202309/shops",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)) Debug CkHttpResponse::ckBodyStr(resp) CkHttpResponse::ckDispose(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" ; } cipher.s code_str.s id.s name.s region.s seller_type.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.shops") While i < count_i CkJsonObject::setCkI(json, i) cipher = CkJsonObject::ckStringOf(json,"data.shops[i].cipher") code_str = CkJsonObject::ckStringOf(json,"data.shops[i].code") id = CkJsonObject::ckStringOf(json,"data.shops[i].id") name = CkJsonObject::ckStringOf(json,"data.shops[i].name") region = CkJsonObject::ckStringOf(json,"data.shops[i].region") seller_type = CkJsonObject::ckStringOf(json,"data.shops[i].seller_type") 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.