【问题标题】:How to use google API in Apps Scripts on Google Sheet?如何在 Google Sheet 上的 Apps Scripts 中使用 google API?
【发布时间】:2021-11-30 04:42:26
【问题描述】:

我知道我的问题听起来有点拗口,所以让我澄清一下:我需要做一些事情,比如将数据从 Google Sheet 带到 AWS(即 Athena),反之亦然。

但是,由于无论如何都需要Google API,我惊讶地发现require()根本不是这种JS孪生语言中的函数。那么,我们如何在上面使用任何第三方库呢?

示例 (github repo):

const {google} = require('googleapis');

【问题讨论】:

  • 您想使用什么 Google API?而且,来自I need to do something like bringing data from Google Sheet to AWS (i.e. Athena), or vice versa.,在这种情况下,我认为在 Google Apps 脚本方面,可能不需要使用 Sheets API。我认为您可以使用Google Spreadsheet service 和Class UrlFetchApp 来实现这一点。如果我误解了您的目标,我深表歉意。
  • fs呢?我需要从 json 文件中读取凭据。那么有什么选择吗?而且似乎我们无法将任何像 .json 这样的文件上传到编辑器。这让我很恼火,因为我需要使用我的凭据。
  • 顺便说一句,基本上我在找google.auth.OAuth2
  • 感谢您的回复。关于What about fs? I need to read the credentials from a json file. So any alternative?,您可以从 Google Drive 上的文件中检索数据。关于And it seems that we have no way to upload any files like .json to the editor.,编辑是什么?关于It annoys me because I need to use my credentials.,对此我深表歉意。关于BTW, essentially I am looking for google.auth.OAuth2.,不幸的是,Google Apps 脚本没有google.auth.OAuth2。但我认为可能可以考虑解决方法。那么,我可以问一下你的目标细节吗?

标签: javascript node.js google-apps-script google-sheets google-api


【解决方案1】:

您可以在 enabling Advanced Services 的 Apps 脚本中使用 Gmail、日历、云端硬盘和大多数其他 Google Workspaces API。

  • 打开 Apps 脚本项目。
  • 点击左侧的编辑器代码。
  • 在左侧的服务旁边,单击添加服务添加。
  • 选择一项高级 Google 服务并点击添加。

这里是an example,介绍如何在 Apps 脚本中使用 Drive API。

【讨论】:

  • 但是我在哪里可以找到google.auth.OAuth2
  • @MemphisMeng 为什么需要 google.auth.OAuth2?您不需要它就可以在 Apps 脚本中使用 Google Workspace API。
猜你喜欢
  • 2023-01-22
  • 1970-01-01
  • 1970-01-01
  • 2020-01-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多