【问题标题】:Specifying which Google account to use when executing a Google Apps Script webapp request指定执行 Google Apps Script webapp 请求时要使用的 Google 帐户
【发布时间】:2012-11-11 10:39:54
【问题描述】:

我有一个浏览器扩展程序,当用户在 Gmail 中阅读电子邮件时,它会从 URL 中抓取 threadId,并使用此 threadId 通过 Google Apps Script API 获取间接数据。

但是,扩展程序不知道可能是几个 Google 帐户中的哪个帐户正在阅读此消息;它只知道我的 Apps Script webapp 的 URL 和 threadId。因此,当它执行 fetch 时,webapp 会将解释请求视为来自默认用户会话,这在某些情况下是错误的,因此在执行 GmailApp.getThreadById(e.parameter.threadId) 时会导致 null

所以我想知道的是是否可以指定查询 webapp 时使用的 Google 帐户。除了要求用户注销所有其他帐户并将当前帐户设置为默认帐户之外,还有其他可能吗?

【问题讨论】:

    标签: gmail google-apps-script google-account


    【解决方案1】:

    很遗憾,Google Apps 脚本不能很好地支持多次登录。请参阅this page 了解更多信息。

    【讨论】:

      【解决方案2】:

      您可以将 authuser 参数添加到您向 Google Apps 脚本发出的请求中。

      authuser 参数的值是当前浏览器会话中记录的所有 Google 帐户的从零开始的索引。

      现在,为了提取您需要发送的索引值,您可以从当前页面中抓取具有 authuser 参数的profiles.google.com 链接,并从中提取您的值并将其与您的请求一起发送。

      链接可能如下所示:

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

      对于gmail,url还包含当前的authuser索引,例如:

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

      上面的这个 URL 在末尾包含 authuser 值 1(在片段之前和 /u/ 之后)

      我知道这是非常复杂的,看起来更像是一个 hack。但我认为这肯定是一种解决方法,直到 Google 提供了一种更好的方法来为您的应用脚本请求指定上下文。

      我希望这可能会有所帮助。

      谢谢。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-07-08
        • 1970-01-01
        • 2014-05-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多