Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

C++ Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
Secrets
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(C++) Google Cloud Storage List Bucket Objects

See more Google Cloud Storage Examples

List the objects in a Google Cloud Storage bucket.

For more information, see https://cloud.google.com/storage/docs/json_api/v1/objects/list

Chilkat C/C++ Library Downloads

MS Visual C/C++

Linux/CentOS C/C++

Alpine Linux C/C++

MAC OS X C/C++

armhf/aarch64 C/C++

C++ Builder

iOS C/C++

Android C/C++

Solaris C/C++

MinGW C/C++

#include <CkStringBuilder.h>
#include <CkHttp.h>
#include <CkHttpResponse.h>
#include <CkJsonObject.h>

void ChilkatSample(void)
    {
    // 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"

    // In this example, Get Google Cloud Storage OAuth2 Access Token, 
    // the service account access token was saved to a text file.  This example fetches the access token from the file..
    CkStringBuilder sbToken;
    sbToken.LoadFile("qa_data/tokens/googleCloudStorageAccessToken.txt","utf-8");

    CkHttp http;
    http.put_AuthToken(sbToken.getAsString());

    // For more info see Cloud Storage Documentation - Objects: list 
    // 
    bool success = http.SetUrlVar("bucket","chilkat-ocean");
    success = http.SetUrlVar("PROJECT_NAME","ChilkatCloud");

    CkHttpResponse *resp = http.QuickGetObj("https://www.googleapis.com/storage/v1/b/{$bucket}/o?project={$ChilkatCloud}");
    if (http.get_LastMethodSuccess() == false) {
        std::cout << http.lastErrorText() << "\r\n";
        return;
    }

    int responseCode = resp->get_StatusCode();
    if (responseCode == 401) {
        std::cout << resp->bodyStr() << "\r\n";
        std::cout << "If invalid credentials, then it is likely the access token expired." << "\r\n";
        std::cout << "Your app should automatically fetch a new access token and re-try." << "\r\n";
        delete resp;
        return;
    }

    std::cout << "Response code: " << responseCode << "\r\n";
    std::cout << "Response body" << "\r\n";

    CkJsonObject json;
    success = json.Load(resp->bodyStr());
    delete resp;

    json.put_EmitCompact(false);

    std::cout << json.emit() << "\r\n";

    // A response code = 200 indicates success, and the response body contains JSON such as this:

    // {
    //   "kind": "storage#objects",
    //   "items": [
    //     {
    //       "kind": "storage#object",
    //       "id": "chilkat-ocean/file with space char.jpg/1555776690752366",
    //       "selfLink": "https://www.googleapis.com/storage/v1/b/chilkat-ocean/o/file%20with%20space%20char.jpg",
    //       "mediaLink": "https://www.googleapis.com/download/storage/v1/b/chilkat-ocean/o/file%20with%20space%20char.jpg?generation=1555776690752366&alt=media",
    //       "name": "file with space char.jpg",
    //       "bucket": "chilkat-ocean",
    //       "generation": "1555776690752366",
    //       "metageneration": "1",
    //       "contentType": "image/jpeg",
    //       "storageClass": "MULTI_REGIONAL",
    //       "size": "6229",
    //       "md5Hash": "LpxZ2/JmI2fcl9/dqF2gSA==",
    //       "crc32c": "9RjgwQ==",
    //       "etag": "CO6WguiH3+ECEAE=",
    //       "timeCreated": "2019-04-20T16:11:30.752Z",
    //       "updated": "2019-04-20T16:11:30.752Z",
    //       "timeStorageClassUpdated": "2019-04-20T16:11:30.752Z"
    //     },
    //     {
    //       "kind": "storage#object",
    // 
    //       "id": "chilkat-ocean/penguins.jpg/1555775749593296",
    //       "selfLink": "https://www.googleapis.com/storage/v1/b/chilkat-ocean/o/penguins.jpg",
    //       "mediaLink": "https://www.googleapis.com/download/storage/v1/b/chilkat-ocean/o/penguins.jpg?generation=1555775749593296&alt=media",
    //       "name": "penguins.jpg",
    //       "bucket": "chilkat-ocean",
    //       "generation": "1555775749593296",
    //       "metageneration": "1",
    //       "contentType": "image/jpeg",
    //       "storageClass": "MULTI_REGIONAL",
    //       "size": "777835",
    //       "md5Hash": "nTd7EM53jEk4s8fixjoimg==",
    //       "crc32c": "ixxYVw==",
    //       "etag": "CNCxnqeE3+ECEAE=",
    //       "timeCreated": "2019-04-20T15:55:49.593Z",
    //       "updated": "2019-04-20T15:55:49.593Z",
    //       "timeStorageClassUpdated": "2019-04-20T15:55:49.593Z"
    //     },
    //     {
    //       "kind": "storage#object",
    //       "id": "chilkat-ocean/starfish.jpg/1628958192639968",
    //       "selfLink": "https://www.googleapis.com/storage/v1/b/chilkat-ocean/o/starfish.jpg",
    //       "mediaLink": "https://www.googleapis.com/download/storage/v1/b/chilkat-ocean/o/starfish.jpg?generation=1628958192639968&alt=media",
    //       "name": "starfish.jpg",
    //       "bucket": "chilkat-ocean",
    //       "generation": "1628958192639968",
    //       "metageneration": "1",
    //       "contentType": "image/jpeg",
    //       "storageClass": "MULTI_REGIONAL",
    //       "size": "6229",
    //       "md5Hash": "LpxZ2/JmI2fcl9/dqF2gSA==",
    //       "crc32c": "9RjgwQ==",
    //       "etag": "COC/tJP2sPICEAE=",
    //       "timeCreated": "2021-08-14T16:23:12.660Z",
    //       "updated": "2021-08-14T16:23:12.660Z",
    //       "timeStorageClassUpdated": "2021-08-14T16:23:12.660Z"
    //     }
    //   ]
    // }

    // Use this online tool to generate parsing code from sample JSON: 
    // Generate Parsing Code from JSON

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
    // See this example explaining how this memory should be used: const char * functions.

    const char *id = 0;
    const char *selfLink = 0;
    const char *mediaLink = 0;
    const char *name = 0;
    const char *bucket = 0;
    const char *generation = 0;
    const char *metageneration = 0;
    const char *contentType = 0;
    const char *storageClass = 0;
    const char *size = 0;
    const char *md5Hash = 0;
    const char *crc32c = 0;
    const char *etag = 0;
    const char *timeCreated = 0;
    const char *updated = 0;
    const char *timeStorageClassUpdated = 0;

    const char *kind = json.stringOf("kind");
    int i = 0;
    int count_i = json.SizeOfArray("items");
    while (i < count_i) {
        json.put_I(i);
        kind = json.stringOf("items[i].kind");
        id = json.stringOf("items[i].id");
        selfLink = json.stringOf("items[i].selfLink");
        mediaLink = json.stringOf("items[i].mediaLink");
        name = json.stringOf("items[i].name");
        bucket = json.stringOf("items[i].bucket");
        generation = json.stringOf("items[i].generation");
        metageneration = json.stringOf("items[i].metageneration");
        contentType = json.stringOf("items[i].contentType");
        storageClass = json.stringOf("items[i].storageClass");
        size = json.stringOf("items[i].size");
        md5Hash = json.stringOf("items[i].md5Hash");
        crc32c = json.stringOf("items[i].crc32c");
        etag = json.stringOf("items[i].etag");
        timeCreated = json.stringOf("items[i].timeCreated");
        updated = json.stringOf("items[i].updated");
        timeStorageClassUpdated = json.stringOf("items[i].timeStorageClassUpdated");
        i = i + 1;
    }
    }

 

© 2000-2024 Chilkat Software, Inc. All Rights Reserved.