2
votes

I'm developing a collaborative intranet site, and I've a problem with Google Apps Script in Google Site. When I develop, I am connected with my user account. But, all the scripts I write will execute under my account's context but I want that my scripts can access another account's context. For example, I've written a script that gives you the number of your unread mails in Gmail. But this script will always give the number of unread mails of the account that is the script's owner. You can understand that is a serious problem for me.

I hope you can help me because I don't know if it is possible and how I can do it.

Thanks a lot.

3

3 Answers

3
votes

It's not possible for a Google Apps Script embedded on a Google Site to run under any other account besides the script's owner. That's a designed limitation due to Google security concerns.

If you're on a custom domain (i.e. Google Apps for Business). It is possible to get the viewing user id, and if you are the domain administrator, some APIs allows the domain administrator to impersonate any user of the domain. I'm not sure GMail allows this though.

But this "impersonate feature" is not built into Apps Script (IRRC), so you'd have to use UrlFetch to access these APIs directly, which is more difficult and cumbersome. But depending on your programming skills that might be simple to do.

0
votes

Seems like they added this functionality in "Deploy Web App" but haven't updated Google Sites part of Google Apps Script to support this new functionality. Please, anyone from team confirm.

0
votes

I believe user1442074 is correct. Under Deploy Web App there is an option:

 Execute this app as:
 User Accessing the web app
 Users will be asked to Authorize the Script

The upside of this is they can modify their own documents. The downside is they cannot access any documents created by the Site administrator (unless they are public).

I know this works with documents. Unsure as to whether it will work with mail.