我遇到了以下错误,我想分享我的解决方案,因为我在网上找不到它。
我的初始代码:
import * as google from 'googleapis';
const sheetsAPI = google.sheets({
version: 'v4',
auth: apiKey
});
给我错误:
google.sheets is not a function
我的解决方案是使用以下内容:
const sheetsAPI = new google.sheets_v4.Sheets({
auth: apiKey
});
这运行正确,正如可用指南所说的问题中的代码一样。
我将接受我自己的答案,但很想知道如果这么大的平台的文档告诉我使用初始代码,为什么我会首先遇到这个问题?
我的解决方案是使用以下内容:
const sheetsAPI = new google.sheets_v4.Sheets({
auth: apiKey
});
这运行正确,正如可用指南所说的问题中的代码一样。
您需要安装并导入
googleapis
安装:
npm install googleapis
# or
yarn add googleapis
然后将其导入为:
const {google} = require('googleapis');
或
import { google } from 'googleapis';
如果您使用 ECMAScript 模块。