I want to set up scripts in sheets creating several menu options for predefined queries. This way normal bob can get his queries, Tina can get hers, and Fredrick in accounting can get the information he needs without out writing his own queries. They can use a fun menu:
screenshot
The data table is set up in BigQuery, and queries work fine using the 'compose query' option. The issue is getting queries written in the script to function in sheets. Here is a nice tutorial by Ido Green on how to go about it. https://greenido.wordpress.com/2013/12/16/big-query-and-google-spreadsheet-intergration/
My problem is getting the permissions to work. I believe I approved the project ID in BigQuery, but I am unsure of how to do this in Drive. This is new to me. Let me know if someone has the step by step. This is the error I get when I try to run the script:
"Exception: No suitable credentials found to access Google Drive. Contact the table owner for assistance."
Thank you for your help
Got the same issue with my Google Apps script.
Steps to fix
Enable Google Drive API in Resources -> Advanced Google Services
Enable Google Drive API in Google Developers Console for this project
Run 'DriveApp.getRootFolder();' to get Drive Auth Scope .
I think the problem is in the OAuth Scopes.
According to this SO question, If you are using the BigQuery web UI and have not explicitly granted access to Drive, it won't work. For example, the first time I tried to "Save to Google Sheets", the BigQuery UI popped up an OAuth prompt asking me to grant access to my Google Drive. After this it could save the results. Try doing this to make sure your credentials have the Drive scope and then "Save View" again.
If you are using your own code to do this, you should request scope 'https://www.googleapis.com/auth/drive' in addition to the 'https://www.googleapis.com/auth/bigquery' scope you are already using to talk to BigQuery.
Also check this SO question and this community page for more information.
Related
I have a Google Apps Script that I am currently using to successfully open a Google Sheets spreadsheet (read-only shared with my account) and perform some reading functions.
I received another spreadsheet that I would like to run similar processes on.
If I try:
SpreadsheetApp.openById("_______") (which works on the other sheet), I get Exception: Service Spreadsheets failed while accessing document with id _____" with this sheet. This spreadsheet is actually an xlsx on Google Drive (but appears it can still open in Google sheets) rather than a native Google sheet so I figured maybe that was the issue...?
So now I'm trying to instead access it as a Google Drive file using DriveApp.getFileById("____"). However now I get an authorization request to allow my script to access Google Drive. When I authorize it, I get:
This app is blocked
This app tried to access sensitive info in your Google Account. To keep your account safe, Google blocked this access.
I haven't found a way to fix this. I'm on a private Google account, not using a company's Apps.
Any ideas?
Found a solution to the permission issue.
To work with Apps Script, I've modified this from #alper's solution which sources #tellowkrinkle's comment.
Do the following:
Go to https://console.developers.google.com and create a new project for yourself
Search for the Google Drive API in the search box at the top, and turn it on
Click OAuth consent screen on the left and set it up.
Assuming your account isn't part of an organization, you'll have to say your app is for external users and in testing
In the required scopes section, add .../auth/docs and .../auth/drive (I'm not sure which needed, it's probably only one of those). This will probably not be available if you didn't complete (2)
Add the accounts you want to use with your copy of gdrive as testers of your app. Only these accounts will be able to use your copy of gdrive, so everyone will have to compile their own (unless someone goes and gets theirs reviewed by Google). I only added my own account because I am the only one using my App Script which uses my Drive.
Click the 3 dots on the top right and select "Project settings". Make note of the "Project number".
Go to your Apps Script. Go to Resources > Cloud Platform project. Insert the project number from (4).
Next time you try to run your Apps Script, you'll be asked to Authorize but this time you'll have the chance to actually do it successfully.
I am trying to use Google Apps Script together with Google Sheets to get API data from a bank to my online table, but looks it is absolutely impossible. Every time I do it, I get these messages:
"Authorization required
Exchange Rate Table needs your permission to access your data on Google
Google sign-in is temporarily disabled for this application
This app has not yet been verified for Google Sign-in".
What kind of authorization Google needs again? I tried to learn at the Google Identity Platform, but found there 10 page instructions with a lot of useful hyperlinks. I need a university course at least to understand it.
This is a known issue regarding Apps Script.
I suggest you star the issue and eventually add a comment saying that you are affected by it.
I made a fun spreadsheet to exercise basic math for my kids, but when they are logged on their kid account, they can not run any scripts (no fancy script, just copy-paste macro). After script authorization request they got error 403.
Chyba 403: access_denied
Podrobnosti požadavku
access_type=offline
login_hint=hanzalek.ben#gmail.com
o2v=1
hl=cs
response_type=none gsession
redirect_uri=https://script.google.com/oauthcallback
state=14621511234839642112
client_id=433541798399-h1ncj2ckkapf2gkcoo59mjv46kem0c88#developer.gserviceaccount.com
display=page
prompt=consent
scope=https://www.googleapis.com/auth/spreadsheets.cu
When I access the spreadsheet from another adult account everything runs.
link to the spreadsheet (you may copy it and use it for your kids if you wish :):
https://docs.google.com/spreadsheets/d/1Jy1hHgyCkkIJv26attxikKpJlYb_hjWXTauXMjVyn8E/edit?usp=sharing
Answer:
It appears that there is a restriction for Kid/Child accounts where Apps Script it not available. As long as your children have restricted accounts, there is nothing you can do about this.
More Information:
I did some testing and was able to reproduce the behaviour. These are the results of my tests:
If the account is a child account, the 403: access_denied error is received when trying to run a script from a Spreadsheet.
If the account is a child account, even if they create a new Sheet themself, they do not have access at all to the script editor. This heavily implies that child accounts do not have any Apps Script permissions/abilities at all.
If the account is not a child account, but the account is set up to be supervised in the family group at https://families.google.com/families, they can both run the script written by another account, and they have access the Script editor.
After searching the Family Link settings for the kid account, I was not able to find any setting which allows this to be turned on. I did some searching and I wasn't able to find any specific documentation either from searching on Google or on Google Help.
I did however find a couple of other Stack Overflow questions in which people have had the same error, and this was also the result of their findings, which I have included below.
Google Issue Tracker:
As there doesn't seem to be anywhere that publically mentions this specific Apps Script restriction, I suggest that you file a bug on Google's Issue Tracker for this, in the linked Apps Script component. They might be able to give you more insight into this behaviour.
In the mean time, it appears the only workaround for this is to have the users of the kids accounts use non-kids accounts while using these Spreadsheets, or maybe looking into embedding the Spreadsheet in a web app and have the scripts execute as you rather than the currently logged-in user. More infor about this can be read here
Relevant Questions:
New Google Account not able to access script.google.com
“Can't visit this page” error when trying to access Google Scripts
References:
Your family on Google
google "kids" apps script 403 - Google Search
Search results for kids apps script 403 - Google Help
Google Issue Tracker
Web Apps | Apps Script | Google Developers
I'm using Apps Script and the OAuth2 for Apps Script Library to connect to a couple Google advertising platforms. Basically, each account team has a Google sheet that automatically gets their campaign data every morning. I've got a couple of these sheets up and running already, but when I try to set up this most recent sheet I'm getting the "Authorization is required to perform that Action" at the very end of the OAuth process. I'm able to start the OAuth dialogue, select an account to authorize, but then I run into the error.
I authorized the script in the script editor before I ran it, and all of my OAuth credentials are correct. I've even deleted and re-created the scripts. The other sheets running the same scripts are still working fine.
What's going on here? I'd appreciate any ideas, I've set up a couple test sheets to see if I can puzzle it out, and now they're all returning the same error.
Update: Everything works properly when run from a different account, so it's looking like it's a problem with my account, specifically. Is there any way to manually check that an Apps Script project has been authorized correctly on a given account, aside from the prompt when the script is first created?
I ended up fixing it by explicitly setting the Authorization Scopes in the manifest. In case anyone finds this question later, here's the links to the relevant Apps Script guides:
Authorization Scopes:
https://developers.google.com/apps-script/concepts/scopes
List of OAuth 2.0 Scopes:
https://developers.google.com/identity/protocols/googlescopes
In my Google spreadsheet, when I go to "Tools->Script Editor..", I get a page saying "No Such User" Error. Any idea how to fix this?
I figure this could be a permissions issue, but not sure how to change permissions if required.
Finally i found the solution accidentally.
The issue is resolved by enabling GoogleAppsScript as part of your drive.
Open Google Drive in your web browser.
Click New > More > + Connect more Apps
and then select GoogleAppsScript.
Once i did this going back to script editor of my spreadsheet, no more gives any error.
Here is the link which contained this step:-
https://developers.google.com/drive/v2/web/quickstart/apps-script
Also there is additional problem about Invalid OAuth Client when trying to run the script. which i faced since each apps script has to be attached to a Google Cloud Project. This is accessible only to the person who originally created the file even after its in the team drive. In which case, you need to make a copy of the apps script available by going into File->Make a copy. And then in the Resources drop down , you will see Cloud Platform Project, upon clicking it you can now give the project number of the Google Cloud Platform project you created on console.cloud.google.com.