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())
Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐