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
(SQL Server) 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
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls. -- CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int DECLARE @iTmp0 int -- Important: Do not use nvarchar(max). See the warning about using nvarchar(max). DECLARE @sTmp0 nvarchar(4000) -- This example assumes the Chilkat API to have been previously unlocked. -- See Global Unlock Sample for sample code. DECLARE @http int -- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END -- 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 DECLARE @jsonToken int -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jsonToken OUT DECLARE @success int EXEC sp_OAMethod @jsonToken, 'LoadFile', @success OUT, 'qa_data/tokens/tiktok-shops.json' IF @success <> 1 BEGIN PRINT 'Failed to load tiktok-shops.json' EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @jsonToken RETURN END DECLARE @queryParams int -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @queryParams OUT EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'app_key', 'APP_KEY' DECLARE @dt int -- Use "Chilkat_9_5_0.CkDateTime" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.CkDateTime', @dt OUT EXEC sp_OAMethod @dt, 'GetAsUnixTimeStr', @sTmp0 OUT, 0 EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'timestamp', @sTmp0 EXEC sp_OAMethod @queryParams, 'UpdateInt', @success OUT, '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 DECLARE @ascending int SELECT @ascending = 1 DECLARE @caseSensitive int SELECT @caseSensitive = 1 EXEC sp_OAMethod @queryParams, 'Sort', NULL, @ascending, @caseSensitive DECLARE @appSecret nvarchar(4000) SELECT @appSecret = 'APP_SECRET' DECLARE @path nvarchar(4000) SELECT @path = '/authorization/202309/shops' -- Build the StringToSign DECLARE @sb int -- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sb OUT EXEC sp_OAMethod @sb, 'Append', @success OUT, @appSecret EXEC sp_OAMethod @sb, 'Append', @success OUT, @path DECLARE @numParams int EXEC sp_OAGetProperty @queryParams, 'Size', @numParams OUT DECLARE @i int SELECT @i = 0 WHILE @i < @numParams BEGIN EXEC sp_OAMethod @queryParams, 'NameAt', @sTmp0 OUT, @i EXEC sp_OAMethod @sb, 'Append', @success OUT, @sTmp0 EXEC sp_OAMethod @queryParams, 'StringAt', @sTmp0 OUT, @i EXEC sp_OAMethod @sb, 'Append', @success OUT, @sTmp0 SELECT @i = @i + 1 END EXEC sp_OAMethod @sb, 'Append', @success OUT, @appSecret DECLARE @crypt int -- Use "Chilkat_9_5_0.Crypt2" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Crypt2', @crypt OUT EXEC sp_OASetProperty @crypt, 'HashAlgorithm', 'SHA256' EXEC sp_OASetProperty @crypt, 'MacAlgorithm', 'HMAC' EXEC sp_OASetProperty @crypt, 'EncodingMode', 'hex_lower' EXEC sp_OAMethod @crypt, 'SetMacKeyString', @success OUT, @appSecret DECLARE @sig nvarchar(4000) EXEC sp_OAMethod @sb, 'GetAsString', @sTmp0 OUT EXEC sp_OAMethod @crypt, 'MacStringENC', @sig OUT, @sTmp0 EXEC sp_OAMethod @jsonToken, 'StringOf', @sTmp0 OUT, 'data.access_token' EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'access_token', @sTmp0 EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'sign', @sig EXEC sp_OAMethod @jsonToken, 'StringOf', @sTmp0 OUT, 'data.access_token' EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'x-tts-access-token', @sTmp0 EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'content-type', 'application/json' DECLARE @resp int EXEC sp_OAMethod @http, 'QuickRequestParams', @resp OUT, 'GET', 'https://open-api.tiktokglobalshop.com/authorization/202309/shops', @queryParams EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT IF @iTmp0 = 0 BEGIN EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @jsonToken EXEC @hr = sp_OADestroy @queryParams EXEC @hr = sp_OADestroy @dt EXEC @hr = sp_OADestroy @sb EXEC @hr = sp_OADestroy @crypt RETURN END DECLARE @json int -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT EXEC sp_OAMethod @resp, 'GetBodyJson', @success OUT, @json EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT PRINT @iTmp0 EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @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" -- } DECLARE @cipher nvarchar(4000) DECLARE @code_str nvarchar(4000) DECLARE @id nvarchar(4000) DECLARE @name nvarchar(4000) DECLARE @region nvarchar(4000) DECLARE @seller_type nvarchar(4000) DECLARE @code int EXEC sp_OAMethod @json, 'IntOf', @code OUT, 'code' DECLARE @message nvarchar(4000) EXEC sp_OAMethod @json, 'StringOf', @message OUT, 'message' DECLARE @request_id nvarchar(4000) EXEC sp_OAMethod @json, 'StringOf', @request_id OUT, 'request_id' SELECT @i = 0 DECLARE @count_i int EXEC sp_OAMethod @json, 'SizeOfArray', @count_i OUT, 'data.shops' WHILE @i < @count_i BEGIN EXEC sp_OASetProperty @json, 'I', @i EXEC sp_OAMethod @json, 'StringOf', @cipher OUT, 'data.shops[i].cipher' EXEC sp_OAMethod @json, 'StringOf', @code_str OUT, 'data.shops[i].code' EXEC sp_OAMethod @json, 'StringOf', @id OUT, 'data.shops[i].id' EXEC sp_OAMethod @json, 'StringOf', @name OUT, 'data.shops[i].name' EXEC sp_OAMethod @json, 'StringOf', @region OUT, 'data.shops[i].region' EXEC sp_OAMethod @json, 'StringOf', @seller_type OUT, 'data.shops[i].seller_type' SELECT @i = @i + 1 END EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @jsonToken EXEC @hr = sp_OADestroy @queryParams EXEC @hr = sp_OADestroy @dt EXEC @hr = sp_OADestroy @sb EXEC @hr = sp_OADestroy @crypt EXEC @hr = sp_OADestroy @json END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.