UrlFetch getting 404 error from spreadsheet URL

纵饮孤独 提交于 2019-11-28 14:09:46

While this technique does not directly use the Advanced Drive Service, it is those permissions that are needed for the script to access your Google Drive files via their URLs.

A note on Issue 3579: Converting spreadsheet as PDF fails with new Sheets provides the hint:

Keep in mind that solution only works if Drive or DriveApp appears somewhere in the script, so that the Drive OAuth scopes are requested and can be passed along. Check to ensure this is true for all scripts.

It's sufficient to add a dummy function containing a DriveApp function call:

/**
 * Dummy function for API authorization only.
 */
function forAuth_() {
  DriveApp.getFileById("Just for authorization"); // https://code.google.com/p/google-apps-script-issues/issues/detail?id=3579#c36
}

Then enable the Advanced Drive Service through "Resources > Advanced Drive Services...", and the developer console. (See this for more info.)


In my case, I had a script that had been working, and then stopped. I believe that when I was originally writing the script, I'd attempted to use the Advanced Drive Service export links (which don't work, btw), so I'd been through enabling the service. But recently, I'd had to reauthorized the script due to other changes, and I think that removed the authorization for Drive at the same time.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!