Can a Google Apps Script Web App get the user's language and time zone?

十年热恋 提交于 2021-02-07 19:24:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!