0

Is there a way to access an object stored in a non-public google bucket using app-script?

i have this function which works for publicly available files, but i cant seem to find any documentation on how to access a non-public bucket?

How do i Authorize an app script to access a bucket?

function import_data_from_bucket() {

var url = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXX.txt';
var text = UrlFetchApp.fetch(url).getContentText(); 
var csv = Utilities.parseCsv(text, ',');   
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
sheet.getRange(1, 1, csv.length, csv[0].length).setValues(csv);

}

Carlo B.
  • 119
  • 2
  • 16

1 Answers1

0

I understand that you want to download objects from a Cloud Storage bucket using Apps Script. If that is the case you could follow this guide to download them all. To replicate these steps on Apps Script you would require to manage the endpoint and headers with UrlFetchApp.fetch() to capture the data. Please, ask me any additional doubt so I can help you better.

Jacques-Guzel Heron
  • 2,480
  • 1
  • 7
  • 16
  • after some additional research, i have figured out how to do this (using AWS s3). I found this bit of code by kmotrebski that generates signed URLs for aws here [link](https://raw.githubusercontent.com/kmotrebski/gas-s3-url-generator/master/UrlGenerator.gs) which allows google sheets to pull in data from non-public storage. I'm sure a similar version can be constructed for google buckets, but i was unable to find it. – Carlo B. Jul 02 '20 at 18:04