TypeError: Cannot read property 'gmail' of undefined

大城市里の小女人 提交于 2019-12-23 23:17:46

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/41558938/typeerror-cannot-read-property-gmail-of-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!