Saturday, December 16, 2017

Re: Office365/SharePoint Online Integration

Thanks for your reply. I found this guide..

https://www.coderedcorp.com/blog/uploading-files-to-sharepoint-with-django-and-pyth/

where the author is trying to do the same thing I'm trying to do. It sounds like he uses the OneDrive API. I've never used APIs before so this will definitely be a learning process. I'm trying to understand how he did this - if you can give me some further advice it would be much appreciated.

It sounds like he first uses python-social-auth to authenticate via Office365/AzureAD then makes the api call with def handle_file_upload:

So to me it sounds like since I already have users authenticated with Office365/AzureAD I can just write a method similar to his that makes the api call? Something like...

def handle_file_upload(file_to_upload):

   # Getting the authenticated user credentials from allauth_office365

   social = request.user.social_auth.get(provider='office365') #Im using a different authentication backend/provider than the author did in the article

   access_token = social.extra_data['access_token']

   # build our header for the api call

   headers = {

       'Authorization' : 'Bearer {0}'.format(access_token),

   }

   # build the url for the api call

   # Look at https://dev.onedrive.com/items/upload_put.htm for reference

   url = 'https://{tenant}.sharepoint.com/api/v2.0/drive/root:/' + file_to_upload.name + ':/content'


    # Make the api call

   response = requests.put(url, data=open(file_to_upload, 'rb'), headers=headers)

   return response




Thanks again for your advice



On Friday, December 15, 2017 at 3:24:30 PM UTC-7, Erik Cederstrand wrote:
> Den 15. dec. 2017 kl. 22.18 skrev Alexander Joseph <alexander...@gmail.com>:
>
> I'm still new to django but I'm building an app that allows users to authenticate through Office365. I'm using this -  https://github.com/Lamelos/django-allauth-office365
> and I got users to be able to successfully sign in with office365 but I now need users to be able to upload documents to the sharepoint online sites within office365. I'm not entirely sure how to go about this. If someone else has any idea or has done something like this before any advice is much appreciated. Since the users are already authenticated with Office365 and, assuming I put the correct permissions/scope in my settings file and dev.microsoft app, I thought maybe I could just try to upload a file from the model like a normal upload path ('https://company.sharepoint.com//SiteName/Shared%20Documents/') but this didn't work. It seemed to upload the file without throwing any exceptions but the file wasn't actually in the directory on SharePoint

Your question doesn't really have anything to do with Django, but I've used https://pypi.python.org/pypi/sharepoint previously with some success to work with SharePoint sites. I don't think it supports file uploads directly, but you could use it as a starting point to explore the Sharepoint SOAP API. But maybe Office365 Sharepoint sites also offer a more modern REST API you could use instead.

Erik

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a14ebabd-9e97-4319-934a-2e6a6f45640d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment