OneDrive Python SDK - create_link for fetching embedded URL

风流意气都作罢 提交于 2019-12-20 05:25:13

问题


OneDrive cloud provides a functionality to get embedded iFrame tags with a publicly accessible URL inside. I'm trying to achieve the same thing using Python OneDrive SDK

There are various features as shown on the documentation page like, uploading, downloading, renaming a file, etc. What I'm trying to achieve here is create an embedded iFrame and get it in response. Something like this.

There is a function inside one of the classes of the SDK called create_link. This function is located inside the same class where other functions like upload are present. onedrivesdk/request/item_request_builder.pyitem_builder_request.py There is also a type argument that can be used. I believe, embed would be the argument that we would pass. However, when I execute client.item(drive='me', id='fileid').create_link('embed') it does not give the same result as it's shown in case of Graph API on this page. What should I do?

My purpose is to basically get a public URL to the excel sheet that I upload via. python code. This URL should not ask for a login.

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)

What I have right now is the item object after I upload the file.


回答1:


In your example post method is missing which basically submits a POST request to the server.

So, the query to create embed links:

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

{
  "type": "embed"
} 

could be executed via Python OneDrive SDK like this:

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

where item_id is id for drive item



来源:https://stackoverflow.com/questions/54327805/onedrive-python-sdk-create-link-for-fetching-embedded-url

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!