我正在尝试通过REST API使用python应用程序将文件上传到sharepoint o365,但是收到错误 任何帮助表示赞赏 提前致谢 请找到下面的脚本
代码:
.observeEventType(.ChildAdded)
答案 0 :(得分:0)
要与Microsoft Sharepoint交互,您需要使用Microsoft Graph API。
以下是https://graph.microsoft.io/en-us/docs
的主页从驱动器中获取文件https://graph.microsoft.io/en-us/docs/api-reference/v1.0/api/item_downloadcontent
另一种选择是使用OneDrive API
导入请求
def handle_file_upload(file_to_upload):
""" Function to upload files to our sharepoint directory """
# Getting the authenticated user credentials from python-social-auth
# This call assumes the user you are trying to access is the logged in user.
social = request.user.social_auth.get(provider='azuread-oauth2')
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 = settings.SOCIAL_AUTH_AZUREAD_OAUTH2_RESOURCE + '/_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
答案 1 :(得分:0)
我建议使用O365访问Microsoft Sharepoint。 不幸的是,缺少有关使用Sharepoint进行操作的文档,但我可以确认它是否有效。