Untitled
plain_text
a month ago
1.3 kB
2
Indexable
Never
import requests # Thay thế các giá trị sau bằng thông tin xác thực của bạn client_id = 'YOUR_CLIENT_ID' client_secret = 'YOUR_CLIENT_SECRET' tenant_id = 'YOUR_TENANT_ID' site_id = 'YOUR_SITE_ID' drive_id = 'YOUR_DRIVE_ID' folder_path = '/sites/{site-id}/drives/{drive-id}/root:/path/to/folder' # Lấy mã truy cập từ Microsoft Graph API def get_access_token(): url = f'https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token' data = { 'grant_type': 'client_credentials', 'client_id': client_id, 'client_secret': client_secret, 'scope': 'https://graph.microsoft.com/.default' } response = requests.post(url, data=data) access_token = response.json()['access_token'] return access_token # Lấy danh sách tệp tin trong thư mục def get_files_in_folder(): access_token = get_access_token() url = f'https://graph.microsoft.com/v1.0/{folder_path}/children' headers = { 'Authorization': f'Bearer {access_token}' } response = requests.get(url, headers=headers) files = response.json()['value'] return files # Gọi hàm để lấy danh sách tệp tin files = get_files_in_folder() # In ra tên các tệp tin for file in files: print(file['name'])