OneDrive Python SDK - create_link for fetching emb

2019-02-27 16:42发布

问题:

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