问题
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