When I try to use Google drive reference it always shows ReferenceError: "Drive" is not defined. (line 16, file "Code").
2 Answers
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

- 7,089
- 6
- 37
- 39
-
thanks bro! here's the line of code `Drive.Files.insert(file, image, {ocr: true});` – Coty Embry Jul 12 '17 at 03:25
-
1@CotyEmbry Happy that it can help you. :) – Sour LeangChhean Sep 01 '17 at 01:33
-
In the "Advanced Google Services" you need to scroll down to see the drive. In the Google Console dashboard, go to "enable API and services", type "drive" in the field, enable it. – JinSnow Sep 07 '17 at 07:52
-
1Unfortunately, enabling the Drive API in the dashboard didn't solve this for me. – Kev Dec 11 '18 at 09:42
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.

- 152
- 2
- 10