I had the following error and thought I’d share my solution as I couldn’t find it online.
My initial code:
import * as google from 'googleapis';
const sheetsAPI = google.sheets({
version: 'v4',
auth: apiKey
});
Gave me the error:
google.sheets is not a function
My solution was rather using the following:
const sheetsAPI = new google.sheets_v4.Sheets({
auth: apiKey
});
This ran correctly as the available guides said the code in the question would.
I’m going to accept my own answer once available, but would love to hear why I could be getting this problem in the first place if the docs for such a big platform told me to use the initial code?
2
Answers
My solution was rather using the following:
This ran correctly as the available guides said the code in the question would.
You need to install and import
googleapis
To install:
Then import it as :
or
If you are using ECMAScript modules.