javascript - "(perhaps it was deleted?)" Spreadsheet Error in Google Scripts - Stack Overflow

I have a small script that grabs some data from a spreadsheet and displays it on a Google Scripts html

I have a small script that grabs some data from a spreadsheet and displays it on a Google Scripts html page - for testing I'm just displaying the sheet name.

It works fine for me but other users get the error : [Error] ScriptError: Document 1sTltxpKjSqgaFjc9-3EQzgtvyErkut2qETsn7SdThLE is missing (perhaps it was deleted?)

The script and Spreadsheet are both public and the user can access the spreadsheet directly.

Link to Spreadsheet

Link to Script page

Google Scripts Code:

function getInfo() {
    var ss = SpreadsheetApp.openById("1sTltxpKjSqgaFjc9-3EQzgtvyErkut2qETsn7SdThLE");
    var ssName = ss.getName();
    var sheet = ss.getSheets()[0];

     return 'Doc: ' + ssName + '. Sheet: ' + sheet.getName();
 }

The javascript in the html is simply:

  function getSheetInfo(data) {
      $('p.data').append(data);
  }

  google.script.run.withSuccessHandler(getSheetInfo)
     .getInfo();

Can anyone shed any light why this sheet isn;t accessible to other users but they can view the sheet? Both are public.

Thanks Rob

I have a small script that grabs some data from a spreadsheet and displays it on a Google Scripts html page - for testing I'm just displaying the sheet name.

It works fine for me but other users get the error : [Error] ScriptError: Document 1sTltxpKjSqgaFjc9-3EQzgtvyErkut2qETsn7SdThLE is missing (perhaps it was deleted?)

The script and Spreadsheet are both public and the user can access the spreadsheet directly.

Link to Spreadsheet

Link to Script page

Google Scripts Code:

function getInfo() {
    var ss = SpreadsheetApp.openById("1sTltxpKjSqgaFjc9-3EQzgtvyErkut2qETsn7SdThLE");
    var ssName = ss.getName();
    var sheet = ss.getSheets()[0];

     return 'Doc: ' + ssName + '. Sheet: ' + sheet.getName();
 }

The javascript in the html is simply:

  function getSheetInfo(data) {
      $('p.data').append(data);
  }

  google.script.run.withSuccessHandler(getSheetInfo)
     .getInfo();

Can anyone shed any light why this sheet isn;t accessible to other users but they can view the sheet? Both are public.

Thanks Rob

Share Improve this question asked May 28, 2014 at 17:56 rob_was_takenrob_was_taken 4132 gold badges5 silver badges15 bronze badges 4
  • 1 Is your script running "as the user accessing the app"? If so, do they have access to the spreadsheet? If this is the case, then this is the expected behavior and the solution is to either share the file to anyone with the link can view or publish the script running as you, the developer. – Henrique G. Abreu Commented May 28, 2014 at 18:18
  • Thanks Henrique. yes, I'm running "as the user accessing the app" as I need to get some personal details of the logged in user. (so can't run as me) And yes, they can access the spreadsheet directly no problems. I'll try with the spreadsheet access settings changes and post back. Thanks for your help. – rob_was_taken Commented May 28, 2014 at 18:32
  • Thanks Henrique that worked. So is there no way to run this without making the sheet publicly accessible? I need to have sensitive data on there. Any way you know? – rob_was_taken Commented May 28, 2014 at 18:48
  • I've made it into a proper answer, since it's quite lengthy. Hope it helps – Henrique G. Abreu Commented May 28, 2014 at 22:55
Add a ment  | 

4 Answers 4

Reset to default 1

If you've deployed your script to run "as the user accessing the app" the spreadsheet must be shared with such user, so that a script running as him can access it. If you have a "general" audience, you'll have to share this spreadsheet with "anyone with the link can view". Unless of course you can change the deployment option to execute the app as you, the developer.

Note that this does not necessarily expose your spreadsheet, because you don't have to handle your users the link, the script code (which can be private only to you) access it on their behalf, and since your code runs from a Google server the spreadsheet link is never leaked.

The only way that the spreadsheet could be leaked is from your manual access to it. E.g. if you open it from a coffee shop or other unsecure network, where someone sniffing or the network admin himself can see the url of sites you navigate to, therefore being able to open the file themselves (since it's shared to anyone with the link).

If your info is really sensitive and you don't want to take any chances, a solution is to save this information somewhere else. For example, if it fits (due to size limitations) you may use the Properties services, or cloud-sql or any other cloud storage.

Another solution is to use a secondary script, published anonymously and running as you, that the "user" script can call using UrlFetch to receive the data from it. In this case there's still a "link-only" security feature, but now your script published link instead of the files, which is way less likely to leak since no one access it but the other script, which is a Google server to server munication. And if someone can hack Google servers munication your data is not secured anyway.

Lastly, probably the best solution, is to use the Drive SDK directly via UrlFetch, on which you can manage the oAuth2 credentials, passing your's instead of your users'. But you'd need to do the oAuth dance in your script, which is not trivial (although there's plenty of code on the internet to help you). Also, there's the advanced Drive service which might help a little, but I'm not sure if it allows you to deal with the oAuth2 yourself.

I had this message e up with an app that accesses a spreadsheet with a limited access list. The users could not access it even though they were authorized because they also had personal accounts on their devices, and there was no opportunity in the browser to switch to their authorized account. But I found a workaround that I thought I would share. By telling the users to open a tab in incognito or private mode, it causes Google to have to prompt for the account and the correct one can be specified.

Hope this helps.

try your luck with DriveApp instead.

    var files = DriveApp.getFilesByName(name).next();

I resolved this problem with new incognito windows google Chrome Ctrl + shift + N

OR creating another user in Google chrome

OR clear cookies.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744186928a4562248.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信