问题
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