Retrieves a list of buckets for a given project.
curl -X GET https://www.googleapis.com/storage/v1/b \
--header "Authorization: Bearer CLOUD_STORAGE_TOKEN" \
--data "project=MY_CLOUD_STORAGE_PROJECT"
#include <CkRestW.h>
#include <CkStringBuilderW.h>
#include <CkJsonObjectW.h>
void ChilkatSample(void)
{
CkRestW rest;
bool success;
// URL: https://www.googleapis.com/storage/v1/b
bool bTls = true;
int port = 443;
bool bAutoReconnect = true;
success = rest.Connect(L"www.googleapis.com",port,bTls,bAutoReconnect);
if (success != true) {
wprintf(L"ConnectFailReason: %d\n",rest.get_ConnectFailReason());
wprintf(L"%s\n",rest.lastErrorText());
return;
}
rest.AddQueryParam(L"project",L"MY_CLOUD_STORAGE_PROJECT");
rest.AddHeader(L"Authorization",L"Bearer CLOUD_STORAGE_TOKEN");
CkStringBuilderW sbResponseBody;
success = rest.FullRequestNoBodySb(L"GET",L"/storage/v1/b",sbResponseBody);
if (success != true) {
wprintf(L"%s\n",rest.lastErrorText());
return;
}
int respStatusCode = rest.get_ResponseStatusCode();
if (respStatusCode >= 400) {
wprintf(L"Response Status Code = %d\n",respStatusCode);
wprintf(L"Response Header:\n");
wprintf(L"%s\n",rest.responseHeader());
wprintf(L"Response Body:\n");
wprintf(L"%s\n",sbResponseBody.getAsString());
return;
}
CkJsonObjectW jsonResponse;
jsonResponse.LoadSb(sbResponseBody);
// See the Online Tool for Generating JSON Parse Code
int i;
int count_i;
const wchar_t *kind = jsonResponse.stringOf(L"kind");
i = 0;
count_i = jsonResponse.SizeOfArray(L"items");
while (i < count_i) {
jsonResponse.put_I(i);
kind = jsonResponse.stringOf(L"items[i].kind");
const wchar_t *id = jsonResponse.stringOf(L"items[i].id");
const wchar_t *selfLink = jsonResponse.stringOf(L"items[i].selfLink");
const wchar_t *projectNumber = jsonResponse.stringOf(L"items[i].projectNumber");
const wchar_t *name = jsonResponse.stringOf(L"items[i].name");
const wchar_t *timeCreated = jsonResponse.stringOf(L"items[i].timeCreated");
const wchar_t *updated = jsonResponse.stringOf(L"items[i].updated");
const wchar_t *metageneration = jsonResponse.stringOf(L"items[i].metageneration");
const wchar_t *location = jsonResponse.stringOf(L"items[i].location");
const wchar_t *storageClass = jsonResponse.stringOf(L"items[i].storageClass");
const wchar_t *etag = jsonResponse.stringOf(L"items[i].etag");
i = i + 1;
}
}
{
"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="
}
]
}