gcf-gmail-codelab icon indicating copy to clipboard operation
gcf-gmail-codelab copied to clipboard

gmail.users.messages.list getting messages.id for a different gmail account I have

Open ajayp opened this issue 3 years ago • 0 comments

I came across a random issue, I am testing this out with multiple gmail accounts.

A few months ago I had one of my gmail account connected up, the token had obviously expired, so I reauthorized access, that all worked as expected.

In the logs, I saw that the gmail.users.messages.list returned a message.id for a different gmail account I am also testing with, and I was able to confirm this by using this https://developers.google.com/gmail/api/reference/rest/v1/users.messages/get against the other account.

This is my code, note that I modified it to be 'me', and looking in the logs, it eventually stops returning the wrong id but the problem is that the actual email that triggered the pub/sub is "skipped".

any ideas?

const getMostRecentMessageWithTag = async (email, historyId) => {
  // Look up the most recent message.
  console.log(`getMostRecentMessageWithTag email: ${email} `);
  const listMessagesRes = await gmail.users.messages.list({
    userId: 'me',   // use 'me' instead of email
    labelIds: ['INBOX'],
    maxResults: 1,
    includeSpamTrash: false
  });
....
    const message = await gmail.users.messages.get({
      userId: 'me',   // use 'me' instead of email
      id: messageId
    });

ajayp avatar Feb 23 '22 23:02 ajayp