Thank you I was able to create the script but I get the following error when trying to get adunits details:
"The caller does not have permission". Details: "The caller does not have permission"
service = discovery.build('adsense', 'v2', credentials = credentials)
request = service.accounts().list(pageSize=50)
# while request is not None:
result = request.execute()
print(result)
accounts = result['accounts']
for account in accounts:
print ('Account with ID "%s" and name "%s" was found. '
% (account['name'], account['displayName']))
# Retrieve the ad units for the provided ad client ID.
request = service.accounts().adclients().adunits().list(
parent=f"accounts/{accountId}/adclients/{adClientId}", pageSize=100)
print(request)
result = request.execute()
but receiving "The caller does not have permission" error although the other service to get account details is working for me. I have the client_id, client_secret and refresh_token with me and able to use the other service i.e service.accounts().list(pageSize=50)
For the ad unit details I also tried the APIs Explorer but getting the same error there as well:
{
"error": {
"code": 403,
"message": "The caller does not have permission",
"status": "PERMISSION_DENIED"
}
}
What permissions do I need to check here which are being denied. Kindly help