0
votes

I am trying to download attachment using Gmail API and below is the code for the that

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.

Currently i am getting Gmail is not defined, i have installed gapi and included it as

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

1 Answers

0
votes

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:

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. Additionally, you can always make API calls without using gapi library.