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 BucketsSee more Google Cloud Storage ExamplesDemonstrates how to retrieve a list of buckets for a given project.
Use ChilkatAx-win32.pkg Procedure Test Token Handle hoJsonToken Boolean iSuccess Handle hoHttp Variant vResp Handle hoResp Integer iResponseCode Handle hoJson String sKind Integer i Integer iCount_i String sId String sSelfLink String sProjectNumber String sName String sTimeCreated String sUpdated String sMetageneration Boolean iIamConfigurationBucketPolicyOnlyEnabled String sLocation String sStorageClass String sEtag 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" Get Create (RefClass(cComChilkatJsonObject)) To hoJsonToken If (Not(IsComObjectCreated(hoJsonToken))) Begin Send CreateComObject of hoJsonToken End Get ComLoadFile Of hoJsonToken "qa_data/tokens/googleCloudStorage.json" To iSuccess If (iSuccess = False) Begin Get ComLastErrorText Of hoJsonToken To sTemp1 Showln sTemp1 Procedure_Return End Get Create (RefClass(cComChilkatHttp)) To hoHttp If (Not(IsComObjectCreated(hoHttp))) Begin Send CreateComObject of hoHttp End Get ComStringOf Of hoJsonToken "access_token" To sTemp1 Set ComAuthToken Of hoHttp To sTemp1 // For more info see Cloud Storage Documentation - Buckets: list // Get ComSetUrlVar Of hoHttp "PROJECT_ID" "chilkattest-1050" To iSuccess Get ComQuickGetObj Of hoHttp "https://www.googleapis.com/storage/v1/b?project={$PROJECT_ID}" 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#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", // "iamConfiguration": { // "bucketPolicyOnly": { // "enabled": false // } // }, // "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", // "iamConfiguration": { // "bucketPolicyOnly": { // "enabled": false // } // }, // "location": "US", // "storageClass": "MULTI_REGIONAL", // "etag": "CAE=" // } // ] // } // 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].projectNumber" To sProjectNumber Get ComStringOf Of hoJson "items[i].name" To sName Get ComStringOf Of hoJson "items[i].timeCreated" To sTimeCreated Get ComStringOf Of hoJson "items[i].updated" To sUpdated Get ComStringOf Of hoJson "items[i].metageneration" To sMetageneration Get ComBoolOf Of hoJson "items[i].iamConfiguration.bucketPolicyOnly.enabled" To iIamConfigurationBucketPolicyOnlyEnabled Get ComStringOf Of hoJson "items[i].location" To sLocation Get ComStringOf Of hoJson "items[i].storageClass" To sStorageClass Get ComStringOf Of hoJson "items[i].etag" To sEtag Move (i + 1) To i Loop End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.