Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(AutoIt) Google Cloud Storage List BucketsSee more Google Cloud Storage ExamplesDemonstrates how to retrieve a list of buckets for a given project.
; 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" $oJsonToken = ObjCreate("Chilkat.JsonObject") Local $bSuccess = $oJsonToken.LoadFile("qa_data/tokens/googleCloudStorage.json") If ($bSuccess = False) Then ConsoleWrite($oJsonToken.LastErrorText & @CRLF) Exit EndIf $oHttp = ObjCreate("Chilkat.Http") $oHttp.AuthToken = $oJsonToken.StringOf("access_token") ; For more info see Cloud Storage Documentation - Buckets: list ; $bSuccess = $oHttp.SetUrlVar("PROJECT_ID","chilkattest-1050") Local $oResp = $oHttp.QuickGetObj("https://www.googleapis.com/storage/v1/b?project={$PROJECT_ID}") If ($oHttp.LastMethodSuccess = False) Then ConsoleWrite($oHttp.LastErrorText & @CRLF) Exit EndIf Local $iResponseCode = $oResp.StatusCode If ($iResponseCode = 401) Then ConsoleWrite($oResp.BodyStr & @CRLF) ConsoleWrite("If invalid credentials, then it is likely the access token expired." & @CRLF) ConsoleWrite("Your app should automatically fetch a new access token and re-try." & @CRLF) Exit EndIf ConsoleWrite("Response code: " & $iResponseCode & @CRLF) ConsoleWrite("Response body" & @CRLF) $oJson = ObjCreate("Chilkat.JsonObject") $bSuccess = $oJson.Load($oResp.BodyStr) $oJson.EmitCompact = False ConsoleWrite($oJson.Emit() & @CRLF) ; 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 Local $sKind Local $i Local $iCount_i Local $sId Local $selfLink Local $sProjectNumber Local $sName Local $sTimeCreated Local $sUpdated Local $sMetageneration Local $bIamConfigurationBucketPolicyOnlyEnabled Local $sLocation Local $storageClass Local $sEtag $sKind = $oJson.StringOf("kind") $i = 0 $iCount_i = $oJson.SizeOfArray("items") While $i < $iCount_i $oJson.I = $i $sKind = $oJson.StringOf("items[i].kind") $sId = $oJson.StringOf("items[i].id") $selfLink = $oJson.StringOf("items[i].selfLink") $sProjectNumber = $oJson.StringOf("items[i].projectNumber") $sName = $oJson.StringOf("items[i].name") $sTimeCreated = $oJson.StringOf("items[i].timeCreated") $sUpdated = $oJson.StringOf("items[i].updated") $sMetageneration = $oJson.StringOf("items[i].metageneration") $bIamConfigurationBucketPolicyOnlyEnabled = $oJson.BoolOf("items[i].iamConfiguration.bucketPolicyOnly.enabled") $sLocation = $oJson.StringOf("items[i].location") $storageClass = $oJson.StringOf("items[i].storageClass") $sEtag = $oJson.StringOf("items[i].etag") $i = $i + 1 Wend |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.