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 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.
-- 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 -- Replace values in all caps with your specific values. -- SHOP_CIPHER and SHOP_ID are returned from this example: Get Authorized Shops 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' EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'shop_cipher', 'SHOP_CIPHER' EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'shop_id', 'SHOP_ID' 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 = '/product/202309/categories' -- 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/product/202309/categories', @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 @hr = sp_OADestroy @resp DECLARE @id nvarchar(4000) DECLARE @is_leaf int DECLARE @local_name nvarchar(4000) DECLARE @parent_id nvarchar(4000) DECLARE @j int DECLARE @count_j int DECLARE @strVal 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.categories' WHILE @i < @count_i BEGIN EXEC sp_OASetProperty @json, 'I', @i EXEC sp_OAMethod @json, 'StringOf', @id OUT, 'data.categories[i].id' EXEC sp_OAMethod @json, 'BoolOf', @is_leaf OUT, 'data.categories[i].is_leaf' EXEC sp_OAMethod @json, 'StringOf', @local_name OUT, 'data.categories[i].local_name' PRINT 'local_name: ' + @local_name EXEC sp_OAMethod @json, 'StringOf', @parent_id OUT, 'data.categories[i].parent_id' SELECT @j = 0 EXEC sp_OAMethod @json, 'SizeOfArray', @count_j OUT, 'data.categories[i].permission_statuses' WHILE @j < @count_j BEGIN EXEC sp_OASetProperty @json, 'J', @j EXEC sp_OAMethod @json, 'StringOf', @strVal OUT, 'data.categories[i].permission_statuses[j]' SELECT @j = @j + 1 END 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.