简体   繁体   English

使用gmail API的Gmail附件

[英]Gmail Attachment using gmail API

I am trying to download attachment using Gmail API and below is the code for the that 我正在尝试使用Gmail API下载附件,以下是该代码

var Data = req.body;
var parts = Data.payload.parts;

for (var i = 0; i < parts.length; i++) {
var part = parts[i];
if (part.filename && part.filename.length > 0) {
  var attachId = part.body.attachmentId;
  var request = gapi.client.gmail.users.messages.attachments.get({
    'id': attachId,
    'messageId': message.id,
    'userId': userId
  });
  request.execute(function(attachment) {
    callback(part.filename, part.mimeType, attachment);
  });
}
} 

I have used the link Gmail API to get the Attachment and since it require autorization as mention so who to pass the refershToken,clientSecret,clientId,accessToken etc..or whether this is required first place. 我已经使用了链接Gmail API来获取附件,并且由于它需要进行人工授信,因此谁可以传递ReferhToken,clientSecret,clientId,accessToken等。或者是否需要将其放在第一位。

Currently i am getting Gmail is not defined, i have installed gapi and included it as 目前我没有定义Gmail,我已经安装了gapi并将其作为

var cs = require("coffee-script/register");
var gapi = require('gapi');`

I haven't used gapi inside of nodejs environment, but from my experience in using gapi library in chrome extensions - after loading gapi script you need to load gmail separatelly - something like this: 我没有在nodejs环境中使用过gapi,但是根据我在chrome扩展中使用gapi库的经验-加载gapi脚本后,您需要单独加载gmail-类似:

gapi.client.load('gmail', 'v1', callback);

And after that you can start using it. 之后,您就可以开始使用它了。 That's probably reason for getting "Gmail is not defined" error. 这可能是出现“未定义Gmail”错误的原因。 Additionally, you can always make API calls without using gapi library. 此外,您始终可以在不使用gapi库的情况下进行API调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM