且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

TypeError:无法读取未定义的属性'gmail'

更新时间:2022-10-14 18:57:54

有3个选项:
1.您没有安装googleapis节点模块。
2.您没有很好地导入它。
3.您没有使用它。



选项1修正:
安装googleapis节点模块:
yarn add googleapis

选项2修正:
在googleapis(V26)的新版本中,我需要将我的导入行更改为以下内容:
var {google } = require('googleapis');

选项3修正:
您可以通过google.client.gmail调用它,也许只需使用google.gmail


let fs = require('fs');
let google = require('googleapis');

getMessage(userId, messageId, callback) {
    let gmail = this.getGmailService();
    var request = google.client.gmail.users.messages.get({
        'userId': userId,
        'id': messageId
    });
    request.execute(callback);
}

when I call this method from a spec

getMessage('abcd123987@gmail.com', '15934550ay626ud09')

it spits out the following error

TypeError: Cannot read property 'gmail' of undefined

any comments/suggestions?

There are 3 options: 1. You didn't install the googleapis node module. 2. You didn't import it well. 3. You didn't use it well.

Option 1 fix: Install the googleapis node module: yarn add googleapis

Option 2 fix: In the new version of googleapis (V26) I needed to change my import line to the following: var {google} = require('googleapis');

Option 3 fix: You are calling it via google.client.gmail, perhaps use just google.gmail