(403) User does not have an AdSense account

1,618 views
Skip to first unread message

Roel

unread,
May 2, 2012, 8:29:20 PM5/2/12
to adsen...@googlegroups.com
Hello,

For a while I have been struggling now to get a script to communicate with a AdSense account that I own via the AdSense API.

As this is thus one single AdSense account that I own myself I decided to choose the service account authentication technique using a certificate (https://developers.google.com/accounts/docs/OAuth2#serviceaccount). A snipplet of the PHP code is given by:

        $client = new apiClient();
       
        $key = file_get_contents(KEY_FILE);
        $client->setClientId(CLIENT_ID);
        $client->setAssertionCredentials(new apiAssertionCredentials(
                SERVICE_ACCOUNT_NAME,
                array('https://www.googleapis.com/auth/adsense.readonly'),
                $key)
        );
       
        $service = new apiAdsenseService($client);
        $results = $service->reports->generate('2012-04-01', '2012-04-31');

I enabled the Adsense Management API, but still when I now run this script I get a response of:

(403) User does not have an AdSense account

The account using which I have created the OAuth keys is the very same account having access to the AdSense page. Thus the same e-mail address appers in the top-right corner.

What could I be doing wrong?

Best,
Roel

Sérgio Gomes

unread,
May 3, 2012, 10:44:14 AM5/3/12
to adsen...@googlegroups.com
Hi Roel,

I'm afraid that accessing the AdSense Management API via service account authentication is not supported, since it's protected user information (and as described in the service account authentication entry in the documentation page you linked to, access to user information is not supported).

This doesn't mean that support couldn't be added in the future, but for now you'll need to stick to web-based or installed authentication for PHP.

Cheers,
Sérgio

---
Sérgio Gomes
Developer Relations

Google UK Limited
Registered Office: Belgrave House, 76 Buckingham Palace Road, London SW1W 9TQ
Registered in England Number: 3977902

----

Eric Haskins

unread,
May 3, 2012, 10:38:59 AM5/3/12
to adsen...@googlegroups.com

Service Accounts wont work when a User is required like in the case of AdSense.  You will need to use oAuth. Even though you have a private key etc

 

Eric Haskins

--
You received this message because you are subscribed to the Google Groups "AdSense API Forum" group.
To view this discussion on the web visit https://groups.google.com/d/msg/adsense-api/-/lqBmSu4ax7YJ.
To post to this group, send email to adsen...@googlegroups.com.
To unsubscribe from this group, send email to adsense-api...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/adsense-api?hl=en.

Andreas Osswald

unread,
May 20, 2014, 12:21:11 PM5/20/14
to adsen...@googlegroups.com
Hi,

I also had the same '(403) User does not have an AdSense account.' problem with service account authentication today. Are you planning to support this functionality one day? The web-based authentication works fine, but unfortunately it is no option in our use case.

Best regards,
Andreas

Jose Alcérreca (AdSense API Team)

unread,
May 20, 2014, 12:27:15 PM5/20/14
to adsen...@googlegroups.com
Hi Andreas,

There is no need for Service Accounts. If you can't use "Web application", you can probably use "Installed application" (see the getting started guide). What's your specific use case?

Cheers,
Jose


---
Jose Alcérreca
Developer Relations

Google UK Limited
Registered Office: Belgrave House, 76 Buckingham Palace Road, London SW1W 9TQ
Registered in England Number: 3977902

ad...@adrastea.com

unread,
May 20, 2014, 12:51:35 PM5/20/14
to adsen...@googlegroups.com
Dear Jose,

Thank you for your quick answer! I have just seen that there are "refresh tokens" which never expire and can create more "access tokens" so that there's only one manual login necessary. Nevertheless, I'm not sure if this works without a web-browser. In the use case I want to run a PHP script regularly through the crontab.

I haven't found a way yet to access the "refresh token" through the PHP library from https://github.com/google/google-api-php-client - but maybe I need to investigate it a bit further. :)

Best regards,
Andreas

Jose Alcérreca (AdSense API Team)

unread,
May 20, 2014, 1:16:49 PM5/20/14
to adsen...@googlegroups.com
Hey Andreas,

You might be looking for the access_type. Set it to offline so that you get a refresh_token.


Cheers,
Jose



---
Jose Alcérreca
Developer Relations

Google UK Limited
Registered Office: Belgrave House, 76 Buckingham Palace Road, London SW1W 9TQ
Registered in England Number: 3977902

ad...@adrastea.com

unread,
May 20, 2014, 1:23:56 PM5/20/14
to adsen...@googlegroups.com
Hey Jose,

Looks like as if it works! Thanks a lot!

Best regards,
Andreas

Bastien DONJON

unread,
Apr 2, 2015, 9:48:48 AM4/2/15
to adsen...@googlegroups.com
Hello,

It's possible to used API AdSense Management with OAuth 2.0 for Server to Server ?

I have a server application to automatic download reports.

I don't see exemple other without user actions.

Thanks

Dean Lukies (Adsense API Team)

unread,
Apr 2, 2015, 12:59:59 PM4/2/15
to adsen...@googlegroups.com
Hello,

you will need to get the token with a one-time, user interaction; after that you can use the token to do server to server.

thanks,
Dean

Bastien DONJON

unread,
Apr 6, 2015, 2:18:11 PM4/6/15
to adsen...@googlegroups.com
Nice. Thanks Dean.

Tseng Yishung

unread,
May 31, 2016, 11:09:56 AM5/31/16
to AdSense API Forum
Hello,

    I still have the same problem.

    Where can I get the one-time token?

    By the way, I use the sample code(python). It works on sample API: sqladmin, but it always fails in adsense. Respond 403 error: User does not have  an AdSense account.

    I use the same service account key, and the API test is working.

Thanks

Dean Lukies (Adsense API Team)

unread,
May 31, 2016, 11:12:51 AM5/31/16
to AdSense API Forum
Hi,

if you follow the getting started guide it will generate the token for you; my suggestion is that you use one of the examples and, once you have it working, modify it to suit your needs.

thanks,
Dean
Reply all
Reply to author
Forward
0 new messages