Retrieves a list of objects in the Google Cloud Storage bucket. The name of the bucket is specified in the URL's path. This example retrieves a listing of the objects in the "chilkat-test" bucket.
curl -X GET https://www.googleapis.com/storage/v1/b/chilkat-bucket/o?project=MY_CLOUD_STORAGE_PROJECT \
--header "Authorization: Bearer CLOUD_STORAGE_TOKEN"
#include <C_CkRestW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkJsonObjectW.h>
void ChilkatSample(void)
{
HCkRestW rest;
BOOL success;
BOOL bTls;
int port;
BOOL bAutoReconnect;
HCkStringBuilderW sbResponseBody;
int respStatusCode;
HCkJsonObjectW jsonResponse;
int i;
int count_i;
const wchar_t *kind;
const wchar_t *id;
const wchar_t *selfLink;
const wchar_t *name;
const wchar_t *bucket;
const wchar_t *generation;
const wchar_t *metageneration;
const wchar_t *contentType;
const wchar_t *timeCreated;
const wchar_t *updated;
const wchar_t *storageClass;
const wchar_t *timeStorageClassUpdated;
const wchar_t *size;
const wchar_t *md5Hash;
const wchar_t *mediaLink;
const wchar_t *crc32c;
const wchar_t *etag;
rest = CkRestW_Create();
// URL: https://www.googleapis.com/storage/v1/b/chilkat-bucket/o?project=MY_CLOUD_STORAGE_PROJECT
bTls = TRUE;
port = 443;
bAutoReconnect = TRUE;
success = CkRestW_Connect(rest,L"www.googleapis.com",port,bTls,bAutoReconnect);
if (success != TRUE) {
wprintf(L"ConnectFailReason: %d\n",CkRestW_getConnectFailReason(rest));
wprintf(L"%s\n",CkRestW_lastErrorText(rest));
CkRestW_Dispose(rest);
return;
}
CkRestW_AddHeader(rest,L"Authorization",L"Bearer CLOUD_STORAGE_TOKEN");
sbResponseBody = CkStringBuilderW_Create();
success = CkRestW_FullRequestNoBodySb(rest,L"GET",L"/storage/v1/b/chilkat-bucket/o?project=MY_CLOUD_STORAGE_PROJECT",sbResponseBody);
if (success != TRUE) {
wprintf(L"%s\n",CkRestW_lastErrorText(rest));
CkRestW_Dispose(rest);
CkStringBuilderW_Dispose(sbResponseBody);
return;
}
respStatusCode = CkRestW_getResponseStatusCode(rest);
if (respStatusCode >= 400) {
wprintf(L"Response Status Code = %d\n",respStatusCode);
wprintf(L"Response Header:\n");
wprintf(L"%s\n",CkRestW_responseHeader(rest));
wprintf(L"Response Body:\n");
wprintf(L"%s\n",CkStringBuilderW_getAsString(sbResponseBody));
CkRestW_Dispose(rest);
CkStringBuilderW_Dispose(sbResponseBody);
return;
}
jsonResponse = CkJsonObjectW_Create();
CkJsonObjectW_LoadSb(jsonResponse,sbResponseBody);
// See the Online Tool for Generating JSON Parse Code
kind = CkJsonObjectW_stringOf(jsonResponse,L"kind");
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jsonResponse,L"items");
while (i < count_i) {
CkJsonObjectW_putI(jsonResponse,i);
kind = CkJsonObjectW_stringOf(jsonResponse,L"items[i].kind");
id = CkJsonObjectW_stringOf(jsonResponse,L"items[i].id");
selfLink = CkJsonObjectW_stringOf(jsonResponse,L"items[i].selfLink");
name = CkJsonObjectW_stringOf(jsonResponse,L"items[i].name");
bucket = CkJsonObjectW_stringOf(jsonResponse,L"items[i].bucket");
generation = CkJsonObjectW_stringOf(jsonResponse,L"items[i].generation");
metageneration = CkJsonObjectW_stringOf(jsonResponse,L"items[i].metageneration");
contentType = CkJsonObjectW_stringOf(jsonResponse,L"items[i].contentType");
timeCreated = CkJsonObjectW_stringOf(jsonResponse,L"items[i].timeCreated");
updated = CkJsonObjectW_stringOf(jsonResponse,L"items[i].updated");
storageClass = CkJsonObjectW_stringOf(jsonResponse,L"items[i].storageClass");
timeStorageClassUpdated = CkJsonObjectW_stringOf(jsonResponse,L"items[i].timeStorageClassUpdated");
size = CkJsonObjectW_stringOf(jsonResponse,L"items[i].size");
md5Hash = CkJsonObjectW_stringOf(jsonResponse,L"items[i].md5Hash");
mediaLink = CkJsonObjectW_stringOf(jsonResponse,L"items[i].mediaLink");
crc32c = CkJsonObjectW_stringOf(jsonResponse,L"items[i].crc32c");
etag = CkJsonObjectW_stringOf(jsonResponse,L"items[i].etag");
i = i + 1;
}
CkRestW_Dispose(rest);
CkStringBuilderW_Dispose(sbResponseBody);
CkJsonObjectW_Dispose(jsonResponse);
}
{
"kind": "storage#objects",
"items": [
{
"kind": "storage#object",
"id": "chilkat-bucket/hedgehogs.jpg/1540253106638630",
"selfLink": "https://www.googleapis.com/storage/v1/b/chilkat-bucket/o/hedgehogs.jpg",
"name": "hedgehogs.jpg",
"bucket": "chilkat-bucket",
"generation": "1540253106638630",
"metageneration": "1",
"contentType": "image/jpeg",
"timeCreated": "2018-10-23T00:05:06.638Z",
"updated": "2018-10-23T00:05:06.638Z",
"storageClass": "MULTI_REGIONAL",
"timeStorageClassUpdated": "2018-10-23T00:05:06.638Z",
"size": "48573",
"md5Hash": "TE1U6fQlD6MOVGaQbwGinQ==",
"mediaLink": "https://www.googleapis.com/download/storage/v1/b/chilkat-bucket/o/hedgehogs.jpg?generation=1540253106638630&alt=media",
"crc32c": "1B2d6g==",
"etag": "CKaepPqhm94CEAE="
},
{
"kind": "storage#object",
"id": "chilkat-bucket/penguins.jpg/1540253106941673",
"selfLink": "https://www.googleapis.com/storage/v1/b/chilkat-bucket/o/penguins.jpg",
"name": "penguins.jpg",
"bucket": "chilkat-bucket",
"generation": "1540253106941673",
"metageneration": "1",
"contentType": "image/jpeg",
"timeCreated": "2018-10-23T00:05:06.941Z",
"updated": "2018-10-23T00:05:06.941Z",
"storageClass": "MULTI_REGIONAL",
"timeStorageClassUpdated": "2018-10-23T00:05:06.941Z",
"size": "777835",
"md5Hash": "nTd7EM53jEk4s8fixjoimg==",
"mediaLink": "https://www.googleapis.com/download/storage/v1/b/chilkat-bucket/o/penguins.jpg?generation=1540253106941673&alt=media",
"crc32c": "ixxYVw==",
"etag": "COndtvqhm94CEAE="
},
{
"kind": "storage#object",
"id": "chilkat-bucket/starfish.jpg/1540253106637454",
"selfLink": "https://www.googleapis.com/storage/v1/b/chilkat-bucket/o/starfish.jpg",
"name": "starfish.jpg",
"bucket": "chilkat-bucket",
"generation": "1540253106637454",
"metageneration": "1",
"contentType": "image/jpeg",
"timeCreated": "2018-10-23T00:05:06.636Z",
"updated": "2018-10-23T00:05:06.636Z",
"storageClass": "MULTI_REGIONAL",
"timeStorageClassUpdated": "2018-10-23T00:05:06.636Z",
"size": "6229",
"md5Hash": "LpxZ2/JmI2fcl9/dqF2gSA==",
"mediaLink": "https://www.googleapis.com/download/storage/v1/b/chilkat-bucket/o/starfish.jpg?generation=1540253106637454&alt=media",
"crc32c": "9RjgwQ==",
"etag": "CI6VpPqhm94CEAE="
}
]
}