ReferenceError: “Drive” is not defined. (line 16, file “Code”) in google app script

[亡魂溺海] 提交于 2019-12-09 13:13:28

问题


When I try to use Google drive reference it always shows ReferenceError: "Drive" is not defined. (line 16, file "Code").


回答1:


I've solves this error by go to:

Resources -> Advanced Google Services -> Enable Drive Api

Note: you need to Enable Drive Api in Google Console




回答2:


In addition to Sour's answer:

If you have multiple libraries, it seems that you have to enable the Drive API in every Google Apps Script Project (not to be confused with a Google Cloud Project) that might use the Drive API, even if the actual call to the API occurs in a different Apps Script Project.

For example, say you have two Apps Script Projects, Util and DoStuffWithSheets. Util contains a function with a call to the Drive API. DoStuffWithSheets imports Util (by going to Resources -> Libraries). DoStuffWithSheets has a function that is triggered by an edit to a Sheet or whatever, and it calls the Util function that uses the Drive API.

It is NOT sufficient for the Drive API to be enabled in Util; it has to be enabled in DoStuffWithSheets.

This goes for Google Apps Script libraries which belong to the same Google Cloud Project in which the Drive API is also enabled. I haven't tested it for libraries which belong to different GC Projects.



来源:https://stackoverflow.com/questions/43838960/referenceerror-drive-is-not-defined-line-16-file-code-in-google-app-scr

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