簡體   English   中英

如何使用谷歌文檔 API 和 Python 將本地圖像添加到谷歌文檔?

[英]How to add local image to google docs using Google docs API and Python?

我想使用 google docs API 從我的本地系統在我的 google doc 中添加圖像,但我讀到它只接受來自http servers的圖像

我嘗試在谷歌驅動器上上傳圖像,然后在我的代碼中使用驅動器圖像 url 但它拋出了一個錯誤。

我不想讓 Internet 從我的本地系統訪問圖像,因為它不安全。

有沒有其他方法可以從我的本地將圖像添加到谷歌文檔?

示例代碼:

{
            "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"
                    }
                }
            }
        }

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

  1. 將圖像上傳到驅動器。
  2. 雙擊它。 和 go 到Get-Link
  3. Anyone with the link的任何人設置為查看者。 並復制文件 ID。 例如: https://drive.google.com/file/d/FILE_ID/view?usp=sharing
  4. Go 到您的 python 腳本並將其添加為 uri
"uri":"https://drive.google.com/uc?export=view&id=FILE_ID",
  1. 運行添加圖像的 function。

這也可以通過Drive API上傳文件並更改上傳請求的權限來實現。

有關更多文檔,請參閱以下內容:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM