I am trying to list column names of a bigquery table via app script.
The code is something like:
var options = {'method': 'get', 'headers' : {'Content-Type':'application/json'}};
Logger.log(options);
var url = 'https://www.googleapis.com/bigquery/v2/projects/some_project_id/datasets/'+datasetId+'/tables/'+tableId
var response = UrlFetchApp.fetch(url, options).getContentText();
However it produces this error;
Request failed for https://www.googleapis.com/bigquery/v2/projects/##### returned code 401. Truncated server response: { "error": { "errors": [ { "domain": "global", "reason": "required", "message": "Login Required", "locationType": "header", ... (use muteHttpExceptions option to examine full response) (line 70, file "Code")
I do not know how to use o-auth to access the bigquery from script. I also need to deploy the app as an add-on so that users can access their tables via the add-on for which they access in bigquery.