Question

I have a browser extension which is scraping the threadId from the URL when the user is reading an email in Gmail, and is using this threadId to fetch circumstantial data using the Google Apps Script API.

The extension do however not know which of maybe several Google accounts are reading this message; it knows only the URL to my Apps Script webapp and the threadId. So when it executes the fetch, the webapp will the interpret request as coming from the default user session, which in some cases is wrong and will thus result in an null when executing GmailApp.getThreadById(e.parameter.threadId).

So what I am wondering is whether it is possible to specify what Google account to use when querying the webapp. Are there any possibilities other than asking the user to log off all other accounts and set the current one as default?

Was it helpful?

Solution

Unfortunately Google Apps Script does not have good support for multiple logins. See this page for more information.

OTHER TIPS

You can add an authuser parameters to the requests you make to your the Google Apps script.

The authuser param's values are zero based indexes for all the Google accounts that are logged in the current browser session.

Now for extracting what index value you need to send, you can scrape the current page for profiles.google.com links that have authuser param and extract your value from them and send it with your requests.

The link might look like this:

https://profiles.google.com/ ... authuser=0

Specifically for gmail, the url also contains the current authuser index, For example:

https://mail.google.com/mail/u/1/#inbox

This URL above contains the authuser value 1 at the end (before the fragment and after /u/)

I know this is very complex and is looks more like a hack. But I think this surely is a workaround, until Google provides a better way to specifying the context for your apps script requests.

I hope this might be helpful.

Thanks.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top