OneDrive Python SDK - create_link 用于获取嵌入式 URL

OneDrive Python SDK - create_link for fetching embedded URL

OneDrive 云提供了一项功能,可以获取内部具有 public 可访问 URL 的嵌入式 iFrame 标签。 我正在尝试使用 Python OneDrive SDK

实现相同的目的

如文档页面所示,有各种功能,如上传、下载、重命名文件等。 我在这里想要实现的是创建一个嵌入式 iFrame 并得到它作为响应。类似于 this.

SDK 的 classes 中有一个函数叫做 create_link。此函数位于同一 class 内,其中存在其他函数,如 uploadonedrivesdk/request/item_request_builder.pyitem_builder_request.py 还有一个可以使用的 type 参数。我相信,embed 将是我们会通过的论点。 但是,当我执行 client.item(drive='me', id='fileid').create_link('embed') 时,它不会给出与在 this 页面上的图表 API 中显示的结果相同的结果。 我该怎么办?

我的目的是基本上得到一个 public URL 到我上传的 excel sheet。 python 代码。 URL 不应要求登录。

def create_link(self, type):
        """Executes the createLink method

        Args:
            type (str):
                The type to use in the method request          

        Returns:
            :class:`ItemCreateLinkRequestBuilder<onedrivesdk.request.item_create_link.ItemCreateLinkRequestBuilder>`:
                A ItemCreateLinkRequestBuilder for the method
        """
        return ItemCreateLinkRequestBuilder(self.append_to_request_url("action.createLink"), self._client, type)

我现在拥有的是上传文件后的项目对象。

在您的示例中缺少 post 方法,它基本上向服务器提交 POST 请求。

因此,创建嵌入链接的查询:

POST /me/drive/items/{item-id}/createLink
Content-Type: application/json

{
  "type": "embed"
} 

可以像这样通过 Python OneDrive SDK 执行:

result = client.item(drive='me', id=item_id).create_link("embed").post()
print(result.link.web_url)

其中 item_id 是驱动器项目的 ID