본문 바로가기
Python

비즈니스용 원드라이브 문서 다운로드

by 앗사비 2024. 2. 13.
728x90
from O365 import Account # pip install o365

TENANT_ID = '...'
CLIENT_ID = '...'
SECRET_ID = '...'

# https://developer.microsoft.com/en-us/graph/graph-explorer
# 공유 받은 파일 : https://graph.microsoft.com/v1.0/me/drive/sharedWithMe 주소로 쿼리 전송
# 내 파일 : https://graph.microsoft.com/v1.0/me/drives/{drive-id}/items/{item-id}/children 주소로 쿼리 전송 
FILE_ID = '...'
DRIVE_ID = '...' #응답 항목 중 parentReference

credentials = (CLIENT_ID, SECRET_ID)

# https://github.com/O365/python-o365?tab=readme-ov-file#authentication
account = Account(credentials, auth_flow_type="credentials", tenant_id=TENANT_ID)

# 인증 테스트
if account.authenticate():
    print('인증 성공')

storage = account.storage()
my_drive = storage.get_drive(DRIVE_ID)
file = my_drive.get_item(FILE_ID)

# 파일 다운로드
download_success = file.download('./')

if download_success:
    print('파일 다운로드 성공')
else:
    print('파일 다운로드 실패')

 

 

https://mrnoobiest.tistory.com/entry/Onedrive-OnlinePython%EC%9D%84-%EC%82%AC%EC%9A%A9%ED%95%98%EC%97%AC-web-Onedrive%EC%9D%98-%EC%97%91%EC%85%80-%ED%8C%8C%EC%9D%BC-%ED%8E%B8%EC%A7%91%EC%97%85%EB%A1%9C%EB%93%9C%EB%8B%A4%EC%9A%B4%EB%A1%9C%EB%93%9C-%ED%95%98%EA%B8%B0

 

[Onedrive Online]Python을 사용하여 web Onedrive의 엑셀 파일 편집,업로드,다운로드 하기

https://~~~~~~~/~~~~~~/onedrive.aspx 로 구성되어 있는 Onedrive에 Python을 사용하여 접근하고 내부에 적재된 파일을 수정하는 코드를 간략하게 작성해보았습니다. -하고자 하는 동작- 1) 로컬 PC에 있는 Excel

mrnoobiest.tistory.com

 

https://learn.microsoft.com/en-us/graph/tutorials/python-app-only?tabs=aad&tutorial-step=1

 

Build Python apps with Microsoft Graph and app-only authentication - Microsoft Graph

In this tutorial, you'll build a Python app that uses the Microsoft Graph API to access data using app-only authentication.

learn.microsoft.com

 

728x90