Hi @BiYO
Have you register app only correctly? You need to grant access to app only by following steps
[https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-apponly-azureacs
Then you need to post request to
https://accounts.accesscontrol.windows.net/tenant_id/tokens/OAuth/2
With following data
client_id = 'xxxx-xxxxx-xxxxxx-xxxx'
client_secret = 'xxxxxxxxxxxxxxxxxx'
tenant = 'tenant' # e.g. https://tenant.sharepoint.com
tenant_id = 'xxxx-xxx-xxxxx-xxx-xxxxx'
client_id = client_id + '@' + tenant_id
data = {
'grant_type':'client_credentials',
'resource': "00000003-0000-0ff1-ce00-000000000000/" + tenant + ".sharepoint.com@" + tenant_id,
'client_id': client_id,
'client_secret': client_secret,
}
headers = {
'Content-Type':'application/x-www-form-urlencoded'
}
url = "https://accounts.accesscontrol.windows.net/tenant_id/tokens/OAuth/2"
r = requests.post(url, data=data, headers=headers)
json_data = json.loads(r.text)
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.