Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

SQL Server Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(SQL Server) Google Cloud Storage List Buckets

See more Google Cloud Storage Examples

Demonstrates how to retrieve a list of buckets for a given project.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

-- 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.