0
votes

I'm trying to replace the contents of a Google Sheet with a BigQuery query.

I'm in the Google Sheet and using a script based on these: https://greenido.wordpress.com/2013/12/16/big-query-and-google-spreadsheet-intergration/ Accessing BigQuery with Google Spreadsheet

All the script does is pull the info from a BigQuery query and write it to a Google Sheet. But if I just run the script, I end up getting an error: BigQuery: No OAuth token with Google Drive scope was found

What do I need to do to get this to work?

3
also it helps in many cases to search for already asked similar questions! I do remember seeing quite a number of related (I think)Mikhail Berlyant
Thanks Mikhail. I did find similar questions before I posted but none of them (as far as I could tell) dealt with my specific issue.Edward Wu

3 Answers

12
votes

After a lot of Googling, I found the answer. Apparently, even though I need to give my script the authority to manage not just my Google Sheet, but also the authority to manage my Google Drive.

All I have to do is add a function to make Google ask me for permission for the script to manage my Drive.

Here's the function:

function usingAppsScriptsToken ()}
  // we need to provoke a drive dialog
  // DriveApp.getFiles()
}

Note that key ingredient is DriveApp.getFiles(), and it still works even though it's commented. When I run the function, I'll get a pop-up window that says "(your script) would like to View and manage the files in your Google Drive". When I allow it, the data import function works.

Source

2
votes

No need to add anything to your code.

You simply need to add an additional scope to the dependencies part of the appscript.json file:

"dependencies": {
  "enabledAdvancedServices": [{
    "userSymbol": "BigQuery",
    "serviceId": "bigquery",
    "version": "v2"
  },
  { 
    "userSymbol": "Drive",
    "serviceId": "drive",
    "version": "v2"
  }]
}

In the View menu you could select to Show the manifest file:

enter image description here

0
votes

Just add

DriveApp.getFiles()

to any function in your project and run it. After your running, you see a window that asks permission to the Drive.

1-st step

2-step

3-rd step

Afterall you can delete this row and everything is will be ok.