【问题标题】:how to use googleapis from apps script如何从应用程序脚本中使用 googleapis
【发布时间】:2014-03-23 15:51:40
【问题描述】:

我的意图:

我想从 google script 调用 Google 日历的 API acl.list() 使用UrlFetchApp.fetch()函数。

问题:

我的 Google 脚本在运行时自身具有 oauth 令牌。问题是 UrlFetchApp.fetch() 是一个单独的 http 请求,需要 oauth 令牌才能工作。

问题:

如何在从该脚本手动调用的 http 请求中重用我的(已授权的)应用程序脚本使用的令牌。可能吗?如果没有,那么我如何为这个请求生成令牌?

理由:

ContactsApp 使用起来很愉快,但它还不需要 ACL 功能。

我的(不工作的)代码:

function pleaseHelp() {
  var calId = "MY_CORRECT_CALENDAR_ID";
  var url = "https://www.googleapis.com/calendar/v3/calendars/" + calId + "/acl";
  var data = {
    "foo" : "foo data",
    "bar" : "data bar...",
  };
  var payload = JSON.stringify(data);
  var options = {
    "method" : "POST",
    "contentType" : "application/json",
    "payload" : payload
  };
  var response = UrlFetchApp.fetch(url, options);
  Logger.log(response);
}

给出异常:“401 Login Required”显然......

在此先感谢您的帮助。

【问题讨论】:

    标签: javascript oauth google-apps-script google-api google-calendar-api


    【解决方案1】:
    【解决方案2】:

    您可以将令牌附加到您正在拨打的电话中。

    例如: https://www.googleapis.com/calendar/v3/calendars/{cal id}/acl?access_token='yourtoken'

    【讨论】:

    • 我如何获得令牌?
    猜你喜欢
    • 2014-10-25
    • 2011-08-06
    • 1970-01-01
    • 1970-01-01
    • 2019-04-24
    • 2021-10-04
    • 2016-05-06
    • 2020-10-26
    • 1970-01-01
    相关资源
    最近更新 更多