问题
Is there any possibility for a GAS published as a Web App executing under the identity of the active user and using the Ui Service for user interface to get the preferred language and time zone of the user?
Session.getActiveUser()
works but you only get the Email Session.getActiveUser().getEmail()
.Session.getTimeZone()
returns the time zone of the script, not of the user.
Could there be a trick to get the web browser ID string with the language preference?
回答1:
Session.getActiveUserLocale() was introduced in 2014 to provide this capability.
回答2:
This is a very interesting question. I think the short answer is that there is no good way for now and you have to ask the users for their locale/language.
I don't see a way to do this on the server side using the APIs you've already discussed. However, I was thinking maybe there is a clever way to do this on the client side and send send it up to the server using the google.script API after getting the locale information from the navigator.language JS call.
Unfortunately, since the HTML/JS you have in your web app gets sanitized for security through Caja, only portion of the normal window.navigator properties are exposed. It seems the only useful properties are userAgent, and platform. Language seems innocuous enough to expose, so this is worth logging a request in the Issue Tracker.
来源:https://stackoverflow.com/questions/12427764/can-a-google-apps-script-web-app-get-the-users-language-and-time-zone