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) Google Cloud Storage List BucketsSee more Google Cloud Storage ExamplesDemonstrates how to retrieve a list of buckets for a given project.
-- 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 requires the Chilkat API to have been previously unlocked. -- See Global Unlock Sample for sample code. -- This example uses a previously obtained access token having permission for the -- scope "https://www.googleapis.com/auth/cloud-platform" DECLARE @jsonToken int -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jsonToken OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END DECLARE @success int EXEC sp_OAMethod @jsonToken, 'LoadFile', @success OUT, 'qa_data/tokens/googleCloudStorage.json' IF @success = 0 BEGIN EXEC sp_OAGetProperty @jsonToken, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @jsonToken RETURN END DECLARE @http int -- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT EXEC sp_OAMethod @jsonToken, 'StringOf', @sTmp0 OUT, 'access_token' EXEC sp_OASetProperty @http, 'AuthToken', @sTmp0 -- For more info see Cloud Storage Documentation - Buckets: list -- EXEC sp_OAMethod @http, 'SetUrlVar', @success OUT, 'PROJECT_ID', 'chilkattest-1050' DECLARE @resp int EXEC sp_OAMethod @http, 'QuickGetObj', @resp OUT, 'https://www.googleapis.com/storage/v1/b?project={$PROJECT_ID}' EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT IF @iTmp0 = 0 BEGIN EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @jsonToken EXEC @hr = sp_OADestroy @http RETURN END DECLARE @responseCode int EXEC sp_OAGetProperty @resp, 'StatusCode', @responseCode OUT IF @responseCode = 401 BEGIN EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT PRINT @sTmp0 PRINT 'If invalid credentials, then it is likely the access token expired.' PRINT 'Your app should automatically fetch a new access token and re-try.' EXEC @hr = sp_OADestroy @resp EXEC @hr = sp_OADestroy @jsonToken EXEC @hr = sp_OADestroy @http RETURN END PRINT 'Response code: ' + @responseCode PRINT 'Response body' 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_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT EXEC sp_OAMethod @json, 'Load', @success OUT, @sTmp0 EXEC @hr = sp_OADestroy @resp EXEC sp_OASetProperty @json, 'EmitCompact', 0 EXEC sp_OAMethod @json, 'Emit', @sTmp0 OUT PRINT @sTmp0 -- A response code = 200 indicates success, and the response body contains JSON such as this: -- { -- "kind": "storage#buckets", -- "items": [ -- { -- "kind": "storage#bucket", -- "id": "chilkat-bucket", -- "selfLink": "https://www.googleapis.com/storage/v1/b/chilkat-bucket", -- "projectNumber": "5332332985", -- "name": "chilkat-bucket", -- "timeCreated": "2018-10-23T00:04:44.507Z", -- "updated": "2018-10-23T00:04:44.507Z", -- "metageneration": "1", -- "iamConfiguration": { -- "bucketPolicyOnly": { -- "enabled": false -- } -- }, -- "location": "US", -- "storageClass": "MULTI_REGIONAL", -- "etag": "CAE=" -- }, -- { -- "kind": "storage#bucket", -- "id": "chilkat-images", -- "selfLink": "https://www.googleapis.com/storage/v1/b/chilkat-images", -- "projectNumber": "5332332985", -- "name": "chilkat-images", -- "timeCreated": "2018-10-23T11:24:43.000Z", -- "updated": "2018-10-23T11:24:43.000Z", -- "metageneration": "1", -- "iamConfiguration": { -- "bucketPolicyOnly": { -- "enabled": false -- } -- }, -- "location": "US", -- "storageClass": "MULTI_REGIONAL", -- "etag": "CAE=" -- } -- ] -- } -- Use this online tool to generate parsing code from sample JSON: -- Generate Parsing Code from JSON DECLARE @kind nvarchar(4000) DECLARE @i int DECLARE @count_i int DECLARE @id nvarchar(4000) DECLARE @selfLink nvarchar(4000) DECLARE @projectNumber nvarchar(4000) DECLARE @name nvarchar(4000) DECLARE @timeCreated nvarchar(4000) DECLARE @updated nvarchar(4000) DECLARE @metageneration nvarchar(4000) DECLARE @iamConfigurationBucketPolicyOnlyEnabled int DECLARE @location nvarchar(4000) DECLARE @storageClass nvarchar(4000) DECLARE @etag nvarchar(4000) EXEC sp_OAMethod @json, 'StringOf', @kind OUT, 'kind' SELECT @i = 0 EXEC sp_OAMethod @json, 'SizeOfArray', @count_i OUT, 'items' WHILE @i < @count_i BEGIN EXEC sp_OASetProperty @json, 'I', @i EXEC sp_OAMethod @json, 'StringOf', @kind OUT, 'items[i].kind' EXEC sp_OAMethod @json, 'StringOf', @id OUT, 'items[i].id' EXEC sp_OAMethod @json, 'StringOf', @selfLink OUT, 'items[i].selfLink' EXEC sp_OAMethod @json, 'StringOf', @projectNumber OUT, 'items[i].projectNumber' EXEC sp_OAMethod @json, 'StringOf', @name OUT, 'items[i].name' EXEC sp_OAMethod @json, 'StringOf', @timeCreated OUT, 'items[i].timeCreated' EXEC sp_OAMethod @json, 'StringOf', @updated OUT, 'items[i].updated' EXEC sp_OAMethod @json, 'StringOf', @metageneration OUT, 'items[i].metageneration' EXEC sp_OAMethod @json, 'BoolOf', @iamConfigurationBucketPolicyOnlyEnabled OUT, 'items[i].iamConfiguration.bucketPolicyOnly.enabled' EXEC sp_OAMethod @json, 'StringOf', @location OUT, 'items[i].location' EXEC sp_OAMethod @json, 'StringOf', @storageClass OUT, 'items[i].storageClass' EXEC sp_OAMethod @json, 'StringOf', @etag OUT, 'items[i].etag' SELECT @i = @i + 1 END EXEC @hr = sp_OADestroy @jsonToken EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @json END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.