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
(PowerBuilder) Google Cloud Storage List BucketsSee more Google Cloud Storage ExamplesDemonstrates how to retrieve a list of buckets for a given project.
integer li_rc oleobject loo_JsonToken integer li_Success oleobject loo_Http oleobject loo_Resp integer li_ResponseCode oleobject loo_Json string ls_Kind integer i integer li_Count_i string ls_Id string ls_SelfLink string ls_ProjectNumber string ls_Name string ls_TimeCreated string ls_Updated string ls_Metageneration integer li_IamConfigurationBucketPolicyOnlyEnabled string ls_Location string ls_StorageClass string ls_Etag // 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" loo_JsonToken = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_JsonToken.ConnectToNewObject("Chilkat.JsonObject") if li_rc < 0 then destroy loo_JsonToken MessageBox("Error","Connecting to COM object failed") return end if li_Success = loo_JsonToken.LoadFile("qa_data/tokens/googleCloudStorage.json") if li_Success = 0 then Write-Debug loo_JsonToken.LastErrorText destroy loo_JsonToken return end if loo_Http = create oleobject // Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0 li_rc = loo_Http.ConnectToNewObject("Chilkat.Http") loo_Http.AuthToken = loo_JsonToken.StringOf("access_token") // For more info see Cloud Storage Documentation - Buckets: list // li_Success = loo_Http.SetUrlVar("PROJECT_ID","chilkattest-1050") loo_Resp = loo_Http.QuickGetObj("https://www.googleapis.com/storage/v1/b?project={$PROJECT_ID}") if loo_Http.LastMethodSuccess = 0 then Write-Debug loo_Http.LastErrorText destroy loo_JsonToken destroy loo_Http return end if li_ResponseCode = loo_Resp.StatusCode if li_ResponseCode = 401 then Write-Debug loo_Resp.BodyStr Write-Debug "If invalid credentials, then it is likely the access token expired." Write-Debug "Your app should automatically fetch a new access token and re-try." destroy loo_Resp destroy loo_JsonToken destroy loo_Http return end if Write-Debug "Response code: " + string(li_ResponseCode) Write-Debug "Response body" loo_Json = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject") li_Success = loo_Json.Load(loo_Resp.BodyStr) destroy loo_Resp loo_Json.EmitCompact = 0 Write-Debug loo_Json.Emit() // 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 ls_Kind = loo_Json.StringOf("kind") i = 0 li_Count_i = loo_Json.SizeOfArray("items") do while i < li_Count_i loo_Json.I = i ls_Kind = loo_Json.StringOf("items[i].kind") ls_Id = loo_Json.StringOf("items[i].id") ls_SelfLink = loo_Json.StringOf("items[i].selfLink") ls_ProjectNumber = loo_Json.StringOf("items[i].projectNumber") ls_Name = loo_Json.StringOf("items[i].name") ls_TimeCreated = loo_Json.StringOf("items[i].timeCreated") ls_Updated = loo_Json.StringOf("items[i].updated") ls_Metageneration = loo_Json.StringOf("items[i].metageneration") li_IamConfigurationBucketPolicyOnlyEnabled = loo_Json.BoolOf("items[i].iamConfiguration.bucketPolicyOnly.enabled") ls_Location = loo_Json.StringOf("items[i].location") ls_StorageClass = loo_Json.StringOf("items[i].storageClass") ls_Etag = loo_Json.StringOf("items[i].etag") i = i + 1 loop destroy loo_JsonToken destroy loo_Http destroy loo_Json |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.