我在Django中构建应用程序并尝试将文件上传到SharePoint Online站点,但我确定(至少)我的API调用的URL错误。我在dev.microsoft.com中拥有分配给该应用程序的相应权限,但在我尝试上传时收到500响应。
这是我试图使用的基本api电话 PUT / sites / {site-id} / drive / items / {parent-id}:/ {filename}:/ content
我可以通过这两种资源来构建网址,但不确定网站ID或父网址。对于{YourSharepointTenant},我从属性的Azure门户获得了租户ID。它是我在我发布的代码中省略的一长串字符
https://www.coderedcorp.com/blog/uploading-files-to-sharepoint-with-django-and-pyth/
https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_put_content
这是我的代码
def save(self, *args, **kwargs):
# Get the authenticated user credentials from office365-allauth
social = request.user.social_auth.get(provider='office365')
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://{YourSharepointTenant}.sharepoint.com/sites/ITSupport/drive/root:/' + design_document + ':/content'
# Make the api call
response = requests.put(url, data=open(design_document, 'rb'), headers=headers)
return response
super(LaserMaskDesign, self).save(*args, **kwargs)
答案 0 :(得分:0)
在您定位图表时,您应该使用该网址https://graph.microsoft.com/beta/sites/siteid/drive .... 站点API是您的入口点,它将为您提供对驱动器的访问权限。请记住,API处于测试阶段,因此尚未准备就绪。 有关此API的更多文档https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/resources/sharepoint