1

I'm struggling to get getMessages() to work.

All I want to do is get the first message from the first thread.

var threads = GmailApp.getInboxThreads(0,1)[0].getMessages()[0];

But all I ever get is the 'Access denied: : Missing access token for authorization. Request: MailboxService.GetThread' exception.

As far as I am aware I cant set an access token as I haven't clicked on a specific message so I am unable to get the token from metadata.

I have tried with all sorts of scopes and reading many other questions but just cant get it to work.

Anyone able to help me?

Code.cs

function buildAddOn() {               
  var threads = GmailApp.getInboxThreads(0,1)[0].getMessages()[0];  
} 

appsscript.json

{
  "oauthScopes": [        
    "https://mail.google.com/",
    "https://www.googleapis.com/auth/gmail.readonly",        
    "https://www.googleapis.com/auth/gmail.addons.execute",        
    "https://www.googleapis.com/auth/gmail.addons.current.message.action",
    "https://www.googleapis.com/auth/gmail.addons.current.message.metadata",
    "https://www.googleapis.com/auth/gmail.addons.current.message.readonly",
    "https://www.googleapis.com/auth/gmail.addons.current.action.compose",
    "https://www.googleapis.com/auth/script.storage"    
],
  "gmail": {
    "name": "Gmail Add-on - First Message",
    "logoUrl": "https://www.gstatic.com/images/icons/material/system/1x/label_googblue_24dp.png",
    "contextualTriggers": [{
      "unconditional": {
      },
      "onTriggerFunction": "buildAddOn"
    }],
    "openLinkUrlPrefixes": [
      "https://mail.google.com/"
    ],
    "primaryColor": "#4285F4",
    "secondaryColor": "#4285F4"
  }
}
Rubén
  • 34,714
  • 9
  • 70
  • 166

0 Answers0