Saturday, March 18, 2023

Digest for adsense-api@googlegroups.com - 2 updates in 1 topic

Kulvinder Tuteja <ascendeum.weblog@gmail.com>: Mar 17 01:16AM -0700

HI Adsense Team,
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()
 
Here I'm using the *publisher id* with the variable accountId and *customer
id* with the variable adClientId
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
 
On Tuesday, 7 March 2023 at 23:22:12 UTC+5:30 Ad Sense API wrote:
 
Hi Kulvinder,
 
Thanks for your email. There is a selection of sample code available at
https://developers.google.com/adsense/management/libraries, including
python examples. Hopefully something there will help.
 
Regards,
Andrew (AdSense API team)
 
ref:_00D1U1174p._5004Q2jWz3m:ref
Ad Sense API <adsenseapi@forumsupport.google>: Mar 17 02:46PM

Hi Kulvinder,
 
Great that you have made progress. I think the missing part is that you need to call service.accounts().adclients().list() with the parameter "accounts/{accountId}". Then you will have the correct value for the adclient to use as the parent for the call to service.accounts().adclients().adunits().list().
 
If you still hit problems, I would recommend experimenting with the API explorer (the "Try this method" box) on the management API documentation page at https://developers.google.com/adsense/management/reference/rest/v2/accounts/list
 
Regards,
Andrew (AdSense API team)
ref:_00D1U1174p._5004Q2jWz3m:ref
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to adsense-api+unsubscribe@googlegroups.com.

Wednesday, March 8, 2023

Digest for adsense-api@googlegroups.com - 2 updates in 1 topic

Kulvinder Tuteja <ascendeum.weblog@gmail.com>: Mar 06 11:14PM -0800

Hi,
I'm trying to create an api script with python for Adsense.
I have already created the application with the scopes and using the
client_id and client_secret I have also generated the refresh token. Is
there a way to initialise a client and service for adsense like it is there
in the admanager API?
 
For instance, I'm using the following code snippet in python to create
oauth using client_d, client_secret and refresh_token
 
try:
oauth2_client = oauth2.GoogleRefreshTokenClient(
client_id, client_secret, refresh_token)
except Exception as err:
return f"Google Refresh Token Authentication Error: {str(err)}"
 
Then I use the following snippet to initialise the client and use a service
 
# Initialize AdManager Client.
client = ad_manager.AdManagerClient(oauth2_client, "DFP API", network_code)
# Initialize a service.
report_service = client.GetService('ReportService')
 
Is there a similar way for Adsense API to initialise a client using
client_id, client_secret and refresh token and then use a service?
Ad Sense API <adsenseapi@forumsupport.google>: Mar 07 05:52PM

Hi Kulvinder,
 
Thanks for your email. There is a selection of sample code available at https://developers.google.com/adsense/management/libraries, including python examples. Hopefully something there will help.
 
Regards,
Andrew (AdSense API team)
ref:_00D1U1174p._5004Q2jWz3m:ref
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to adsense-api+unsubscribe@googlegroups.com.