📜

Understanding Google Apps Script Session Class

Feb 24, 2025

Lecture Notes: Class Session | Apps Script | Google for Developers

Overview of Google Apps Script Session Class

  • The Session class in Google Apps Script provides access to session information such as:
    • User's email address (in certain circumstances)
    • User's language setting

Key Methods of the Session Class

  • getActiveUser()

    • Returns: User
    • Retrieves information about the current user.
    • Limitations: User's email may not be accessible if security policies restrict it or if script runs without explicit user authorization.
  • getActiveUserLocale()

    • Returns: String
    • Retrieves the language setting of the current user (e.g., 'en' for English).
  • getEffectiveUser()

    • Returns: User
    • Retrieves information about the user under whose authority the script runs.
    • In web apps set to execute as "me," it returns the developer's account.
  • getScriptTimeZone()

    • Returns: String
    • Retrieves the script's time zone.
    • Note: Script time zone defaults to the owner’s time zone but can be changed in project properties.
  • getTemporaryActiveUserKey()

    • Returns: String
    • Provides a temporary key unique to the active user.
    • This key is non-identifying and rotates every 30 days.

Deprecated Methods

  • getTimeZone()
    • Previously returned the script's time zone. Now deprecated.
  • getUser()
    • Previously returned the current user. Now deprecated.

Important Details

  • Access to user information often requires authorization with scopes like https://www.googleapis.com/auth/userinfo.email.
  • Security restrictions prevent access to certain user details in contexts without explicit authorization.

Additional Resources

Feedback and Updates

  • Content is licensed under the Creative Commons Attribution 4.0 License.
  • Last updated on 2024-12-02.

Connect with the Community