Xojo Plugin Google Cloud Storage: List Buckets

Back to Index

Retrieves a list of buckets for a given project.

Documentation: https://cloud.google.com/storage/docs/json_api/v1/buckets/list

CURL Command

curl -X GET https://www.googleapis.com/storage/v1/b \
    --header "Authorization: Bearer CLOUD_STORAGE_TOKEN" \
    --data "project=MY_CLOUD_STORAGE_PROJECT"

Xojo Plugin Example

Dim rest As New Chilkat.Rest
Dim success As Boolean

//  URL: https://www.googleapis.com/storage/v1/b
Dim bTls As Boolean
bTls = True
Dim port As Int32
port = 443
Dim bAutoReconnect As Boolean
bAutoReconnect = True
success = rest.Connect("www.googleapis.com",port,bTls,bAutoReconnect)
If (success <> True) Then
    System.DebugLog("ConnectFailReason: " + Str(rest.ConnectFailReason))
    System.DebugLog(rest.LastErrorText)
    Return
End If

success = rest.AddQueryParam("project","MY_CLOUD_STORAGE_PROJECT")

success = rest.AddHeader("Authorization","Bearer CLOUD_STORAGE_TOKEN")

Dim sbResponseBody As New Chilkat.StringBuilder
success = rest.FullRequestNoBodySb("GET","/storage/v1/b",sbResponseBody)
If (success <> True) Then
    System.DebugLog(rest.LastErrorText)
    Return
End If

Dim respStatusCode As Int32
respStatusCode = rest.ResponseStatusCode
If (respStatusCode >= 400) Then
    System.DebugLog("Response Status Code = " + Str(respStatusCode))
    System.DebugLog("Response Header:")
    System.DebugLog(rest.ResponseHeader)
    System.DebugLog("Response Body:")
    System.DebugLog(sbResponseBody.GetAsString())
    Return
End If

Dim jsonResponse As New Chilkat.JsonObject
success = jsonResponse.LoadSb(sbResponseBody)

//  See the Online Tool for Generating JSON Parse Code
Dim i As Int32
Dim count_i As Int32

Dim kind As String
kind = jsonResponse.StringOf("kind")
i = 0
count_i = jsonResponse.SizeOfArray("items")
While i < count_i
    jsonResponse.I = i
    kind = jsonResponse.StringOf("items[i].kind")
    Dim id As String
    id = jsonResponse.StringOf("items[i].id")
    Dim selfLink As String
    selfLink = jsonResponse.StringOf("items[i].selfLink")
    Dim projectNumber As String
    projectNumber = jsonResponse.StringOf("items[i].projectNumber")
    Dim name As String
    name = jsonResponse.StringOf("items[i].name")
    Dim timeCreated As String
    timeCreated = jsonResponse.StringOf("items[i].timeCreated")
    Dim updated As String
    updated = jsonResponse.StringOf("items[i].updated")
    Dim metageneration As String
    metageneration = jsonResponse.StringOf("items[i].metageneration")
    Dim location As String
    location = jsonResponse.StringOf("items[i].location")
    Dim storageClass As String
    storageClass = jsonResponse.StringOf("items[i].storageClass")
    Dim etag As String
    etag = jsonResponse.StringOf("items[i].etag")
    i = i + 1
Wend

Sample JSON Response Body

{
  "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",
      "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",
      "location": "US",
      "storageClass": "MULTI_REGIONAL",
      "etag": "CAE="
    }
  ]
}