Your flow is a bit short. REST call for datasets seems OK, but as far as I know, you have to request the access token by authorization code, not client credentials alone.
1) Get authorization code
Depends on your flow, for website it will be received during logon process or call to /oauth2/authorize with { 'response_type':'code }
2) Get access token
With authorization code in a variable, you have to modify your request to include to authorization code, like this (grant_type and code fields are altered):
p_url = 'https://login.microsoftonline.com/' + 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' + '/oauth2/token'
data = { 'grant_type':'authorization_code',
'client_id': 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
'client_secret': 'L------------------------------------------=',
'code': authorizationCodeForSingedInUser,
'resource':'https://analysis.windows.net/powerbi/api' }
r = requests.post(url=p_url, data=data)
Basically saying, you have to have a user account that accesses the Power BI resource. Your website (clientid + secret) are not authorized by itself. There must be a user involved.
What's more, afaik only "organization account" users can access power bi.
To be explicit and underline the main cause in this thread, post and comments: Power BI REST API can only be used via User with credentials with Organizational Account and be already signed in (activated) Power BI on Power BI portal. You can check if REST Api will work by checking if this user is able to use Power BI portal manually.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…