Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can not run trivial app script bound to new blank document - get "This app is blocked"

I am unable to run any app script in my google account - even one created by me bound to a new document created by me. When I do, I get an "This App is Blocked" error. Note that this is different from the the "Sign in temporarily disabled for this app" failure mode mentioned elsewhere, and the solution for that problem has no effect on this one.

To test, I created a new spreadsheet while logged into my personal google account and put the value ONE in cell A1...

enter image description here

I then opened the Tools->Script editor from the menu bar of this spreadsheet and entered the following trivial script...

enter image description here

I then click on the run icon from the script editor menu bar with the function "myFunction" selected from the pulldown.

I get an "authorization required" popup and so I click "Review Permissions"...

enter image description here

I then get a "Choose an account" popup and click on my account (the only logged in account, and the same account I was logged into when I created the sheet and the script)...

enter image description here

I then get an "App Blocked" popup. Checking the execution log shows that the script did not run.

enter image description here

What is causing this popup and how can I prevent this so I can run app scripts?

NOTE: I see many other questions describing more complicated versions of this issue but none have useful answers. I am hoping this ultra simple version of the issue will help narrow it down and get a resolution.

More unexpected behavior:

If I put the code into the onLoad() function it works fine and never even asks me for authorization.

If I enter this code: enter image description here

...and then quit out and reload the sheet, then I get this in the execution logs... enter image description here

Again, this is with no authorization popups at all. The sheet loads without interruption and then the entry is in the execution logs. So this would seem to not be a case of not having the right permissions somewhere since code clearly can access the sheet.

Legacy editor

Identical behavior under the legacy editor...

enter image description here

Other accounts

I can repeat these exact same steps on a different google account and it works fine, so this problem appears to be linked to my account. Many others on the internet have noted the same finding. Seems like there might be some hidden (probably unintional) setting attached to the account that gets switched somehow and then thereafter the account is not able to manually authorize scripts to run.

Changing Project

I check and this script is in the "Default" project as expected...

enter image description here

According to this page,

For most applications and scripts, you never need to see or adjust this default GCP project—Apps Script handles all the necessary interactions with the Google Cloud Platform automatically.

Since I have nothing to lose, tried creating a new project in the Google Cloud Platform console, and then tried assigning this script to that new project. Unfortunately when I tried, I got the normal "Authorization needed" popup which lead to this opdd page...

enter image description here

Clicking on the "Troubleshoot this problem" link takes me to this page...

enter image description here

...which seems to say that I do not have the permissions to troubleshoot problems on my own account.

This again seems to suggest there is something misconfigured about my account on google servers. :/

like image 929
bigjosh Avatar asked Mar 15 '21 07:03

bigjosh


People also ask

Can a bound script run as a web app?

When a bound script is run as a web app or via the Apps Script API, these methods are not available. Bound scripts can customize Google Sheets, Docs, and Forms by adding custom menus and dialog boxes or sidebars. Keep in mind, however, that a script can only interact with the user interface for the current instance of an open file.

Does Apps Script block access to calendar API?

For personal accounts (rather than Google Workspace accounts) it looks like Apps Script blocks access to Calendar API and other sensitive information APIs. I was seeing the error message: "This app tried to access sensitive info in your Google Account.

Why can't I access spreadsheet or calendar scripts in Google Apps?

"This app tried to access sensitive info in your Google Account. To keep your account safe, Google blocked this access." 1. You will probably need to set up a Google Cloud Platform (GCP) Project if you want to access Spreadsheet or Calendar scripts. You can link the GCP Project ID in the Project Settings panel of your Apps Script project.

When is a script bound to a Google Docs file?

A script is bound to a Google Sheets, Docs, Slides, or Forms file if it was created from that document rather than as a standalone script . The file a bound script is attached to is referred to as a "container".


3 Answers

Unfortunately there are no good answers there. Lots of people like me wake up one random morning to find that they can not run any new App Scripts in their account any more.

I've found a workaround that works great... but will make you very sad.

This issue does not affect code that runs automatically, so functions like onOpen() and onEdit() run just fine and have full access to the bound document. You heard that right- google blocks code that the user explicitly requests to run to protect their data, but code that runs silently and automatically anytime a sheet is opened or modified is free to run and access (and change!) whatever data it wants.

So to let the user run your code, you pick a cell inside the spreadsheet that either has a value that changes whenever you want your code to run, or you make a special cell called "Edit this cell to run the program".

Then you put your code inside the onEdit() and (if desired) check to see to see if the special cell was updated. If so, then run your arbitrary code. It has full access to the spreadsheet and can read and update cells at will and can also write to the log.

Note that you must close the sheet and re-open it for the code to take effect.

Here is what my demo spreadsheet looks like...

enter image description here

...and here is the demo code...

function onEdit(e) {
  var range = e.range;
  const triggerCell = "B2";
  if( e.range.getA1Notation() === triggerCell){
    var sheet = SpreadsheetApp.getActiveSheet();
    var data = sheet.getDataRange().getValues();
    var rangeB1 =sheet.getRange("B1");
    var rangeB2 =sheet.getRange("B2");
    var date = Utilities.formatDate(new Date(), Intl.DateTimeFormat().resolvedOptions().timeZone, "HH:mm:ss"); 
    rangeB2.setValue("Code ran at " + date );
    Logger.log( date + ": B1=" + rangeB1.getValue() );
  }
}

Here is a demo video...

https://youtu.be/ypuLaUWn1R8

I've said it before, I'll say it again - if you were thinking about using Google Cloud Services for anything then think again. This is crap built on top of crap that no one at google understands and it occasionally breaks suddenly and catastrophically, and there is no one who can even tell you what is going on much less how or when or if it is going to get fixed.

like image 160
bigjosh Avatar answered Oct 24 '22 21:10

bigjosh


I ran into this for the first time today but my issue seems to be due to:

  • created a sheet on a shared drive owned by a different organization
  • my organization uses the legacy apps script interface, the shared drive organization uses the new apps script interface

Using an account from the shared drive organization to create the script solved my issue.

like image 31
Onjuku Avatar answered Oct 24 '22 22:10

Onjuku


This error

This app is blocked

seems to be a new error affecting certain Google accounts. This is reported to Google. Kindly star(add a star ★ to it on top left) to the following issues and comment to get Google developers to prioritize this issue:

  • https://issuetracker.google.com/issues/176138626

  • https://issuetracker.google.com/issues/181220763

Some workarounds:

  • #15 Creating a new GCP and linking it.

  • #12 Turning on Less Secure Apps

  • #10

    • Checking accounts security page
    • Turning off advanced protection
    • Unlock Captcha

This issue does NOT seem to be related to another issue 145162820:

"Sign in temporarily disabled for this app"

The error messages are different.

like image 41
TheMaster Avatar answered Oct 24 '22 22:10

TheMaster