Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to upload files to onedrive using msgraph-sdk-python?

I'm not a newbie when it comes to python (nor a professional), but this is the first time I'm trying something like this.

I would like to upload files to OneDrive using an python script. Sounds simple right? Well apparently it's more then I can handle.

From what I've seen so far the onedrive-sdk-python I was using apparently doesn't work anymore (source: https://github.com/OneDrive/onedrive-sdk-python/issues/119) because it's being decommissioned.

The new SDK to use is the one for Microsoft Graph I guess? But the github (https://github.com/MicrosoftArchive/msgraph-sdk-python) doesn't really mention how to set up the new Oauth2 authentication, get a token and use the client in python. The links mentioned in the authentication section don't work for me, I get error messages like: "AADSTS900144: The request body must contain the following parameter: 'client_id'."

I looked on stackoverflow for similar questions but most of them are about the old onedrive-sdk and the most recent one I could find was almost 3 months old. The response there was that it was still under development.

I guess the problems I've been having are all related to the Microsoft Graph still being in development, but I was wondering if someone managed to get it to work and if they could point me in the right direction to get the authentication setup and getting me started on uploading files to OneDrive.

Some details in case it matters:

  • Rasbian 9 Stretch
  • Python 2.7.13 & Python 3.5.3 (tried both)
  • OneDrive business account

Many thanks to anyone who can point me in the right direction :)

like image 202
gendragongfly Avatar asked Mar 07 '19 21:03

gendragongfly


People also ask

Can Python connect to OneDrive?

Build an ETL App for Microsoft OneDrive Data in PythonYou can now connect with a connection string. Use the connect function for the CData Microsoft OneDrive Connector to create a connection for working with Microsoft OneDrive data.


1 Answers

I'm afraid the SDK you're using is no longer being actively maintained. From the ReadMe:

This library is no longer actively supported. To integrate Microsoft Graph into your Python solution, we recommend using REST and taking a look at our new Python samples and documentation.

To answer your question on tokens, these are not technically issued by Microsoft Graph. They're issued by Azure Active Directory (or Outlook.com for personal accounts). You obtain a token using OAuth 2.0.

You are, however, on the right track. Before you can do anything with Microsoft Graph, you're going to need to obtain an OAuth token. The good news here is there's a sample Python project that walks you through how this process works: Python authentication samples for Microsoft Graph.

like image 190
Marc LaFleur Avatar answered Oct 19 '22 13:10

Marc LaFleur