I have an issue with oauth-scopes and bigquery. I've gotten this (querying a google spreadsheet from bigquery) to work in the (non google ads) scripts environment by manually setting oauthScopes but since this doesn't seem to be an option in ads-scripts i'm not sure how to best proceed.
function main() {
const sheetUrl = "
https://docs.google.com/spreadsheets/d/............."
const projectId = "......"
let queryResults = BigQuery.Jobs.insert({
configuration: {
query:{
query: "SELECT * FROM test",
useLegacySql: false,
tableDefinitions: {
"test": {
sourceUris: [sheetUrl],
autodetect: true,
sourceFormat: "GOOGLE_SHEETS",
}
}
},
}
}, projectId);
const jobId = queryResults.jobReference.jobId;
// Check on status of the Query Job.
let sleepTimeMs = 500;
while (!queryResults.jobComplete) {
Utilities.sleep(sleepTimeMs);
sleepTimeMs *= 2;
queryResults = BigQuery.Jobs.getQueryResults(projectId, jobId);
}
// Get all the rows of results.
// Append the headers.
let rows = queryResults.rows;
while (queryResults.pageToken) {
queryResults = BigQuery.Jobs.getQueryResults(projectId, jobId, {
pageToken: queryResults.pageToken
});
rows = rows.concat(queryResults.rows);
}
if (!rows) {
Logger.log('No rows returned from query: ' + query);
rows = [];
}
Logger.log(rows)
}