python 如何通过 api 访问 sharepoint 的数据
【代码】python 如何通过 api 访问 sharepoint 的数据。
·
import requests
tenant = 'yourtenant.onmicrosoft.com'
client_id = 'your-client-id'
client_secret = 'your-client-secret'
# 获取访问令牌
token_url = f'https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token'
token_data = {
'grant_type': 'client_credentials',
'client_id': client_id,
'client_secret': client_secret,
'scope': f'https://{tenant}/.default'
}
token_r = requests.post(token_url, data=token_data)
token = token_r.json().get('access_token')
# 使用访问令牌访问SharePoint API
site_url = f'https://{tenant}/_api/web'
headers = {
'Authorization': f'Bearer {token}',
'Accept': 'application/json;odata=verbose'
}
response = requests.get(site_url, headers=headers)
print(response.json())
更多推荐
所有评论(0)