如何使用 Google 文档 API 在特定位置插入图像

how to insert an image in a specific location using Google Docs API

我设法使用 batchUpdate 将文本插入到文档中的特定位置,但我找不到任何资源来说明如何只对图像执行相同的操作。任何有关此事的文件将不胜感激。我的文本替换功能如下所示:

async function updateDoc(docs, auth, documentId) {
    try {
        await docs.documents.batchUpdate({
            auth,
            documentId: documentId,
            requestBody: {
                requests
            }
        });
    } catch (error) {
        console.log(error)
    }
}

如果图片有类似的东西就好了。

  • 您想将图像插入 Google Document with Google Docs API.
  • 您想使用带有 Node.js 的 googleapis 来实现此目的。
  • 您已经能够使用 Docs API.API.
  • 获取和放置 Google 文档的值

如果我的理解是正确的,这个答案怎么样?请将此视为几个可能的答案之一。

当它向 Google Document with Docs API 插入图像时,在当前阶段,它使用图像的 URL。示例脚本如下

示例脚本:

请为您的脚本使用 requests

const requests = [{
  insertInlineImage: {
    location: {index: 1},
    uri: "https://cdn.sstatic.net/Sites/Whosebug/company/img/logos/so/so-logo.png"
  }
}];
  • 在这个请求正文中,Whosebug的标志被插入到Google文档中正文的顶部。

注:

  • 当您要插入特定索引时,首先请使用documents.get文档API中的方法检索索引API。
  • 如果要在Google驱动器中使用上传的图片,请在Google驱动器中使用URL的直接link。在这种情况下,请分享图片并将其插入到上述请求正文中。

参考:

如果我误解了您的问题并且这不是您想要的方向,我深表歉意。