Google 日历 API 和节点 js - "googleAuth is not a constructor" 问题
Google calendar API and node js - "googleAuth is not a constructor" issue
我正在尝试在 Node 上设置 Google 日历 API,使用出现的 Node.js 快速启动 here
完成前 3 个步骤和 运行 我的 quickstart.js 检查它是否有效(我从快速入门复制并粘贴)后,我收到以下错误:
"TypeError: googlAuth is not a constructor"
它指的是这行代码:
var auth = new googleAuth();
googleAuth 声明如下:
var googleAuth = require('google-auth-library');
我无法在网上找到任何解决方案。
完整代码在上面的link第三步。
提前致谢,
阿萨夫
我认为这主要是 nodejs 和 google 库安装问题。我的系统是 运行 node v8.2.1
,我能够正确执行 nodejs 快速启动。尝试安装最新的 nodejs 并再次执行这些行。
npm install googleapis --save
npm install google-auth-library@0.* --save
Google 最近发布的版本 1.0.0
。如果你没有安装版本 npm
就会安装最新的。在这种情况下,您的代码应该是:
const {GoogleAuth} = require('google-auth-library');
const auth = new GoogleAuth();
版本已经改变,就像这里的答案一样。根据新的 docs,您必须像这样要求包:
const gal = require('google-auth-library');
const auth = new gal.GoogleAuth();
const jwtClient = new gal.JWT();
const oAuth2Client = new gal.OAuth2Client();
...
// if you're using Node 6+, you might find this convenient:
const {GoogleAuth, JWT, OAuth2Client} = require('google-auth-library');
以前的老办法是这样的:
var GoogleAuth = require('google-auth-library');
var auth = new GoogleAuth();
var jwtClient = new auth.JWT();
var oAuth2Client = new auth.OAuth2();
基本上改变的是引用方式GoogleAuth
。它现在是整个包的一部分,而不是主要导出。
这个改变对我有用!
我正在尝试在 Node 上设置 Google 日历 API,使用出现的 Node.js 快速启动 here
完成前 3 个步骤和 运行 我的 quickstart.js 检查它是否有效(我从快速入门复制并粘贴)后,我收到以下错误:
"TypeError: googlAuth is not a constructor" 它指的是这行代码:
var auth = new googleAuth();
googleAuth 声明如下:
var googleAuth = require('google-auth-library');
我无法在网上找到任何解决方案。
完整代码在上面的link第三步。 提前致谢, 阿萨夫
我认为这主要是 nodejs 和 google 库安装问题。我的系统是 运行 node v8.2.1
,我能够正确执行 nodejs 快速启动。尝试安装最新的 nodejs 并再次执行这些行。
npm install googleapis --save
npm install google-auth-library@0.* --save
Google 最近发布的版本 1.0.0
。如果你没有安装版本 npm
就会安装最新的。在这种情况下,您的代码应该是:
const {GoogleAuth} = require('google-auth-library');
const auth = new GoogleAuth();
版本已经改变,就像这里的答案一样。根据新的 docs,您必须像这样要求包:
const gal = require('google-auth-library');
const auth = new gal.GoogleAuth();
const jwtClient = new gal.JWT();
const oAuth2Client = new gal.OAuth2Client();
...
// if you're using Node 6+, you might find this convenient:
const {GoogleAuth, JWT, OAuth2Client} = require('google-auth-library');
以前的老办法是这样的:
var GoogleAuth = require('google-auth-library');
var auth = new GoogleAuth();
var jwtClient = new auth.JWT();
var oAuth2Client = new auth.OAuth2();
基本上改变的是引用方式GoogleAuth
。它现在是整个包的一部分,而不是主要导出。
这个改变对我有用!