Sample code for 30+ languages & platforms
AutoIt

Google Cloud Storage List Buckets

See more Google Cloud Storage Examples

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

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

; 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")
$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")
$oResp = ObjCreate("Chilkat.HttpResponse")
$bSuccess = $oHttp.HttpNoBody("GET","https://www.googleapis.com/storage/v1/b?project={$PROJECT_ID}",$oResp)
If ($bSuccess = 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