【问题标题】:How to obtain Google Docs document identifier in Alternative Runtime Docs Add-on如何在 Alternative Runtime Docs Add-on 中获取 Google Docs 文档标识符
【发布时间】:2021-06-20 21:40:46
【问题描述】:

大约一周前,Alternative Runtime 向公众发布 (general documentation)

我目前正在使用 Node.js 进行开发。我希望实现的是,在 Google 文档中打开插件(或单击某些按钮)时,我可以获得当前打开的文档的 Docs 文档 ID,并使用 Google Docs API 操作文档。

在摆弄之后,我设法收到了homepageTrigger (documentation) 的有效载荷。在正文中,我确实得到了多个令牌,但不幸的是,docs 字段为空。我的第一个假设是,在请求范围 documents.currentonly (documentation) 时,我将获得 Docs 文档 ID,因此我可以开始使用 Docs API 并操作文档。

我第二次尝试获取 Docs 文档 ID 是不使用 homepageTrigger,而是使用 OnFileScopeGrantedTrigger。但是,这需要我使用 CardService。替代运行时确实存在一个新的Card Framework based on JSON,但我找不到任何使用 JSON 实现以下目标的方法:

CardService.newEditorFileScopeActionResponseBuilder() .requestFileScopeForActiveDocument().build();

(source documentation for the code above).

TLDR:如何使用基于新替代运行时的插件获取当前打开的 Google Docs 文档的 Docs 文档 ID?

【问题讨论】:

  • 你好,你能把你一直使用的代码贴出来吗?“在摆弄之后,我设法收到了homepageTrigger的有效载荷”?

标签: node.js google-apps-script google-docs-api


【解决方案1】:

Google 的文档是最糟糕的,我也在想同样的事情。 下面是用于在 Express 中返回 JSON 化响应的 sn-p,它构建了授权文档的提示。

基本上,这有助于您在此处定义响应对象: https://developers.google.com/workspace/add-ons/reference/rpc/google.apps.card.v1

res.json({
  renderActions: {
    hostAppAction: {
      editorAction: {
        requestFileScopeForActiveDocument: {},
       },
    },
  },
});

【讨论】:

  • 有效!感谢您花时间发布解决方案,从文档中弄清楚这一点一定很痛苦?
猜你喜欢
  • 2021-04-30
  • 1970-01-01
  • 2022-01-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多