Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(DataFlex) Google Cloud Storage List Bucket ObjectsSee more Google Cloud Storage ExamplesList the objects in a Google Cloud Storage bucket. For more information, see https://cloud.google.com/storage/docs/json_api/v1/objects/list
Use ChilkatAx-win32.pkg Procedure Test Handle hoSbToken Boolean iSuccess Handle hoHttp Boolean iSuccess Variant vResp Handle hoResp Integer iResponseCode Handle hoJson String sId String sSelfLink String sMediaLink String sName String sBucket String sGeneration String sMetageneration String sContentType String sStorageClass String sSize String sMd5Hash String sCrc32c String sEtag String sTimeCreated String sUpdated String sTimeStorageClassUpdated String sKind Integer i Integer iCount_i String sTemp1 Boolean bTemp1 // 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.. Get Create (RefClass(cComChilkatStringBuilder)) To hoSbToken If (Not(IsComObjectCreated(hoSbToken))) Begin Send CreateComObject of hoSbToken End Get ComLoadFile Of hoSbToken "qa_data/tokens/googleCloudStorageAccessToken.txt" "utf-8" To iSuccess Get Create (RefClass(cComChilkatHttp)) To hoHttp If (Not(IsComObjectCreated(hoHttp))) Begin Send CreateComObject of hoHttp End Get ComGetAsString Of hoSbToken To sTemp1 Set ComAuthToken Of hoHttp To sTemp1 // For more info see Cloud Storage Documentation - Objects: list // Get ComSetUrlVar Of hoHttp "bucket" "chilkat-ocean" To iSuccess Get ComSetUrlVar Of hoHttp "PROJECT_NAME" "ChilkatCloud" To iSuccess Get ComQuickGetObj Of hoHttp "https://www.googleapis.com/storage/v1/b/{$bucket}/o?project={$ChilkatCloud}" To vResp If (IsComObject(vResp)) Begin Get Create (RefClass(cComChilkatHttpResponse)) To hoResp Set pvComObject Of hoResp To vResp End Get ComLastMethodSuccess Of hoHttp To bTemp1 If (bTemp1 = False) Begin Get ComLastErrorText Of hoHttp To sTemp1 Showln sTemp1 Procedure_Return End Get ComStatusCode Of hoResp To iResponseCode If (iResponseCode = 401) Begin Get ComBodyStr Of hoResp To sTemp1 Showln sTemp1 Showln "If invalid credentials, then it is likely the access token expired." Showln "Your app should automatically fetch a new access token and re-try." Send Destroy of hoResp Procedure_Return End Showln "Response code: " iResponseCode Showln "Response body" Get Create (RefClass(cComChilkatJsonObject)) To hoJson If (Not(IsComObjectCreated(hoJson))) Begin Send CreateComObject of hoJson End Get ComBodyStr Of hoResp To sTemp1 Get ComLoad Of hoJson sTemp1 To iSuccess Send Destroy of hoResp Set ComEmitCompact Of hoJson To False Get ComEmit Of hoJson To sTemp1 Showln sTemp1 // 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 Get ComStringOf Of hoJson "kind" To sKind Move 0 To i Get ComSizeOfArray Of hoJson "items" To iCount_i While (i < iCount_i) Set ComI Of hoJson To i Get ComStringOf Of hoJson "items[i].kind" To sKind Get ComStringOf Of hoJson "items[i].id" To sId Get ComStringOf Of hoJson "items[i].selfLink" To sSelfLink Get ComStringOf Of hoJson "items[i].mediaLink" To sMediaLink Get ComStringOf Of hoJson "items[i].name" To sName Get ComStringOf Of hoJson "items[i].bucket" To sBucket Get ComStringOf Of hoJson "items[i].generation" To sGeneration Get ComStringOf Of hoJson "items[i].metageneration" To sMetageneration Get ComStringOf Of hoJson "items[i].contentType" To sContentType Get ComStringOf Of hoJson "items[i].storageClass" To sStorageClass Get ComStringOf Of hoJson "items[i].size" To sSize Get ComStringOf Of hoJson "items[i].md5Hash" To sMd5Hash Get ComStringOf Of hoJson "items[i].crc32c" To sCrc32c Get ComStringOf Of hoJson "items[i].etag" To sEtag Get ComStringOf Of hoJson "items[i].timeCreated" To sTimeCreated Get ComStringOf Of hoJson "items[i].updated" To sUpdated Get ComStringOf Of hoJson "items[i].timeStorageClassUpdated" To sTimeStorageClassUpdated Move (i + 1) To i Loop End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.