2017-12-20 23 views
0

Django에서 응용 프로그램을 작성하고 SharePoint 온라인 사이트에 파일을 업로드하려고하지만 적어도 API 호출에 대해 URL을 잘못 읽은 것 같습니다. 내가 dev.microsoft.com에서 응용 프로그램에 할당 된 적절한 권한을 가지고 있지만 업로드하려고하면 다시 500 응답을 얻을.SharePoint API 호출 파일 업로드

이 내가 사용하려고 해요 기본 API를 호출입니다 PUT/사이트/{사이트 ID}/드라이브/아이템/{부모-ID}/{파일 이름} :/컨텐츠 나 '

이러한 2 가지 리소스로 이동하여 URL을 작성하지만 사이트 ID 또는 상위 ID를 알 수는 없습니다. {YourSharepointTenant}의 경우 Azure Portal에서 tenant-id 속성을 받았습니다. 내 코드에서 생략 된 문자의 그것의 긴 목록은 여기

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

당신이 사용해야하는 그래프를 타겟팅으로 내 코드 여기

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

게시 그 URL 대신 https://graph.microsoft.com/beta/sites/siteid/drive .... 그것은 귀하의 진입 점이며 드라이브 하나에 액세스 할 수있는 사이트 API입니다. API는 베타 버전이므로 제작 준비 상태가 아닙니다. 이 API에 대한 자세한 설명서는 여기 https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/resources/sharepoint

+0

답장을 보내 주셔서 감사합니다. 어제이 리소스를 발견하여 정확한 URL을 알아 냈습니다 https://developer.microsoft.com/en-us/graph/graph-explorer# 헤더에 내 자격 증명을 추가하는 방법을 알아야합니다. 저자가 기사에서 사용하고있는 패키지를 사용하고 있지 않기 때문입니다. 다음과 같은 작업을 수행해야합니다. https://stackoverflow.com/questions/30278892/django-allauth-get-credentials-to-make-further-requests-on-behalf- of-the-the-user – user3005684