Error : Access denied: : Missing access token for authorization. Request: MailboxService.GetThread.

245 views
Skip to first unread message

Aayesha Shrestha

unread,
Jun 12, 2019, 3:10:53 AM6/12/19
to google-apps-sc...@googlegroups.com
I'm trying to get messages from the Gmail Thread using this code : 
var mails = GmailApp.search('in:sent');
Logger.log(mails[0].getMessages());

But it gives this error : 
Access denied: : Missing access token for authorization. Request: MailboxService.GetThread.

In a stackoverflow question, it was mentioned that adding this scope: https://www.googleapis.com/auth/gmail.readonly  will work. But I'm still stuck with this error since a few days. 

Also, here are the scopes I've included.

Eric Koleda

unread,
Jun 17, 2019, 11:22:18 AM6/17/19
to Google Apps Script Community
Are you writing a Gmail add-on, or just a regular script? If not an add-on, then remove all of those add-on-related scopes, as they are conflicting with the gmail.readonly scope. If you are writing an add-on then lost the gmail.readonly scope and set the current message access token as shown in the docs:


- Eric

Aayesha Shrestha

unread,
Jun 18, 2019, 1:46:49 AM6/18/19
to Google Apps Script Community
I'm working with the add-on and I cannot get the current message access token as all this has to happen without opening any message. Without opening the sent message, I have to get the mail in the sent item with index '0' i.e, the most recently sent, so that I can track the message.

Eric Koleda

unread,
Jun 18, 2019, 8:13:19 PM6/18/19
to google-apps-sc...@googlegroups.com
I see. The gmail.readonly scope does everything the gmail.addons.current.message.metadata scope does (and more), so you can just remove the latter. Be aware that the gmail.readonly scope is restricted, and comes with additional policy requirements (if you want to publish your add-on for the public).

- Eric

--
You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/PcQRqBoKBUA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-script-c...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-apps-script-community.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/241df9f1-4c17-4a57-b77a-302120d11c33%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages