Google Apps Script UrlFetchApp returning Unauthorized Error 401

女生的网名这么多〃 提交于 2019-11-29 17:15:42

The scopes provided are insufficient to access the document. To access it, you'd need documents scope as well. Edit the manifest file to have these scopes:

"oauthScopes": ["https://www.googleapis.com/auth/script.external_request","https://www.googleapis.com/auth/documents"],

Or add a dummy call to Document App in your script:

DocumentApp.getActiveDocument();

Based on comments from Tanaike, It seems that Documents scope wasn't enough, but Spreadsheet scope is also needed, even though we don't access spreadsheets. Alternatively, Drive's readonly scope is required.

Spreadsheet+Document scope:

Manifest:

"oauthScopes": ["https://www.googleapis.com/auth/script.external_request",
    "https://www.googleapis.com/auth/documents"
    "https://www.googleapis.com/auth/spreadsheets"],

Or add a dummy call to Document App+SpreadsheetApp in your script:

//DocumentApp.getActiveDocument();
//SpreadsheetApp.getActive();

Drive scope:

Manifest:

"oauthScopes": ["https://www.googleapis.com/auth/script.external_request",
    "https://www.googleapis.com/auth/drive.readonly"],

Or add a dummy call to DriveApp in your script:

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