4
我的代碼如下獲得Gmail收件箱,(上述代碼作爲在谷歌開發者網站的NodeJS的例子中給出是相同。)使用的node.js和google-API
function listLabels(auth) {
var gmail = google.gmail({ auth: auth, version: 'v1' });
var emails = gmail.users.messages.list({
includeSpamTrash: false,
maxResults: 500,
q: "",
userId: 'me'
}, function (err, results) {
console.log(results.messages);
});
}
我得到對象數組含有ID和線程ID
現在,如果我輸入這些ID
到這些
function getMessage(messageId,auth) {
var requestt = google.gmail({ auth: auth, version: 'v1' }).users.messages.get({
'userId': 'me',
'id': messageId
});
console.log(requestt)
requestt.execute(function(response){
console.log(response);
});
}
我得到錯誤,
TypeError: requestt.execute is not a function
at getMessage (/home/jay/Projects/gmailwebapi/index.js:122:11)
at /home/jay/Projects/gmailwebapi/index.js:113:7
at OAuth2Client._postRequest (/home/jay/Projects/gmailwebapi/node_modules/google-auth-library/lib/auth/oauth2client.js:381:3)
at postRequestCb (/home/jay/Projects/gmailwebapi/node_modules/google-auth-library/lib/auth/oauth2client.js:343:10)
at Request._callback (/home/jay/Projects/gmailwebapi/node_modules/google-auth-library/lib/transporters.js:103:7)
at Request.self.callback (/home/jay/Projects/gmailwebapi/node_modules/google-auth-library/node_modules/request/request.js:198:22)
at emitTwo (events.js:100:13)
at Request.emit (events.js:185:7)
at Request.<anonymous> (/home/jay/Projects/gmailwebapi/node_modules/google-auth-library/node_modules/request/request.js:1057:14)
at emitOne (events.js:95:20)
Workerd罰款... request.execute不是在請求對象只。 – Jay
任何方式批量處理?假設有10個ID? –
@ItzikGili Google爲其API提供了[**批量支持**](https://stackoverflow.com/questions/35343365/gmail-rest-api-batch-support-for-getting-messages),但是我不確定Gmail API JavaScript客戶端是否擁有它。 – Tholle