如何使用Google文档API和Python将本地图像添加到Google文档

我想使用 google docs API 从我的本地系统在我的 google doc 中添加图像,但我读到它只接受来自http servers的图像

我想使用 google docs API 从我的本地系统在我的 google doc 中添加图像,但我读到它只接受来自http servers的图像

我试图上传谷歌驱动器上的图像,然后在我的代码中使用驱动器图像 URL,但它抛出一个错误。

我不想让互联网从我的本地系统访问图像,因为它不会是安全的。

有没有其他方法可以从我的本地添加图像到谷歌文档?

示例代码 (taken from Tanaike's solution):

{
            "insertInlineImage": {
                "location": {
                    "segmentId": header_id,
                    "index": 0
                },
                "uri": "https://stackoverflow.design/assets/img/logos/so/logo-stackoverflow.png",
                # This is a sample image.
                "objectSize": {
                    "width": {
                        "magnitude": 100,
                        "unit": "PT"
                    }
                }
            }
        }
2

您可以按照以下步骤操作:

将映像上载到驱动器。

双击它。然后转到Get-Link

Anyone with the link设置为 Viewer。并复制文件 ID。例如:https://drive.google.com/file/d/FILE_ID/view?usp=sharing

转到您的 python 脚本并将其添加为 uri

"uri":"https://drive.google.com/uc?export=view&id=FILE_ID",

运行添加图像的函数。

这也可以通过Drive API上传文件并更改上传请求的权限来实现。

有关更多文档,请参考以下内容:

Multipart Upload Manage sharing

本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处

(529)
Word内容控件-字段:从字段中的数据在文档上自动执行 QR码
上一篇
角4:如何从Excel中读取数据
下一篇

相关推荐

发表评论

登录 后才能评论

评论列表(4条)