Service Account for AdSense Management API 1.1

646 views
Skip to first unread message

Peter Diamant

unread,
May 8, 2012, 9:46:21 PM5/8/12
to AdSense API Forum
Hi

I'm developing an application to create AdSense Reports
automatically. As we want to run this as a service, we do not want to
have a User manually logging in to Authenticate, so we need to run it
using a "Service Account".

I have read on another post that Service Account Authentication isn't
yet available for the AdSense Management API. Can you confirm whether
or not this is correct? And if so, when will Service Accounts be
avaialble to use with the Adsense management API? We need to have our
service up and running within the month.

If Service Accounts can be used, can I use the latest Google APIs
Client Library for .NET to access the AdSense API with a Service
Account?

Thanks

Sérgio Gomes

unread,
May 9, 2012, 9:59:28 AM5/9/12
to adsen...@googlegroups.com
Hi Peter,

I'm afraid you can't use service accounts with the AdSense Management API, since it accesses protected user data.

You'll need to use the standard web-based or installed OAuth 2.0 flows instead, and run through the authorisation flow once. You can, however, save your authentication data for subsequent runs, so that you only need to perform the authentication step once.

You can take a look at the AuthorizationManager class used by the .NET samples to get an idea of how to persist your credential data between runs: http://code.google.com/p/google-api-dotnet-client/source/browse/SampleHelper/AuthorizationMgr.cs?repo=samples

Hope this helps!

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


---

Peter Diamant

unread,
May 11, 2012, 2:13:58 AM5/11/12
to AdSense API Forum
Hi Sergio

Thanks for the quick response. I’ll look into that.

My next problem (which is Google's problem!), is that there is a major
bug in Version 1.1 of the .Net Beta Client API Library.

Fortunately, I've fixed it in my version of the client library source.

The problem is that the HttpWebRequestBuilder that constructs the REST
service URI uses an IDictionary for the query parameters. This will
not work for all calls to the service because some query parameters
are repeated, in my particular case; the Metric key for the Generate
Reports call has multiple values.

Build and run your AdSense.Sample in the GoogleApisSamples solution
and you will see a crash. You also have the report start and end
dates the wrong way around in the sample which doesn't help.

I've fixed it to allow multiple values for a particular query string
parameter. I can send you my code if you want.

Thanks

Peter


On May 9, 11:59 pm, Sérgio Gomes <sergio.go...@google.com> wrote:
> Hi Peter,
>
> I'm afraid you can't use service accounts with the AdSense Management API,
> since it accesses protected user data.
>
> You'll need to use the standard web-based or installed OAuth 2.0 flows
> instead, and run through the authorisation flow once. You can, however,
> save your authentication data for subsequent runs, so that you only need to
> perform the authentication step once.
>
> You can take a look at the AuthorizationManager class used by the .NET
> samples to get an idea of how to persist your credential data between
> runs:http://code.google.com/p/google-api-dotnet-client/source/browse/Sampl...

Sérgio Gomes

unread,
May 22, 2012, 7:28:50 AM5/22/12
to adsen...@googlegroups.com
Hi Peter,

Apologies for the late response, looks like your message got stuck in the review queue.

That's odd, I tested the samples quite thoroughly. Have you tried assigning an array to a parameter, instead of repeating it? That's generally the way that repeated HTTP parameters get mapped onto programming languages like C#.

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


---

Peter Diamant

unread,
Jun 1, 2012, 12:15:15 AM6/1/12
to adsen...@googlegroups.com
Hi Sergio
 
Your sample code did attach an array to the parameter, unfortunately your .net version of HttpWebRequestBuilder cannot handle an array for a parameter with more than one value without crashing.
 
Try running your .Net AdSense.Sample console example and you will see that it crashes because the reportRequest.Metric parameter at line 52 in GenerateReport.cs has more than one parameter in the list.
 
Regards
 
Peter
 

--
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/-/Dt2KenYyFq0J.

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.

Sérgio Gomes

unread,
Jun 1, 2012, 12:33:06 PM6/1/12
to adsen...@googlegroups.com
Hi Peter,

I've tried this again on my end, and everything seems to work normally, so I am inclined to think this is a problem with the client library itself (perhaps the specific version you're using).

Could you try updating the client library and, if that doesn't solve the issue, file a bug at http://code.google.com/p/google-api-dotnet-client/issues/list ?

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


---
To unsubscribe from this group, send email to adsense-api+unsubscribe@googlegroups.com.

Peter Diamant

unread,
Jun 3, 2012, 8:46:48 PM6/3/12
to adsen...@googlegroups.com
Hi Sergio
 
It is indeed a bug with your .Net client library code as I indicated in my last email, specifically the HttpWebRequestBuilder class.
 
I finished my AdSense project over two weeks ago and it's working fine thank you very much (with the tweaks I made to your client library code).
 
I'm not really interested in filing bug reports at Google, unless of course Google wants to give me a job.
 
I was just trying to help you out with your buggy .Net client library, that's all.
 
Cheers
 
Peter

To view this discussion on the web visit https://groups.google.com/d/msg/adsense-api/-/ZqOQX_ryVoIJ.

To post to this group, send email to adsen...@googlegroups.com.
To unsubscribe from this group, send email to adsense-api...@googlegroups.com.

Sérgio Gomes

unread,
Jun 5, 2012, 9:50:10 AM6/5/12
to adsen...@googlegroups.com
Hi Peter,

The bug report is just a way of providing more specific information in order for us to debug the issue, particularly because I've been unable to replicate it. It would be very useful if you could at least let us know which version of the client library you're using.

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


---

Peter Diamant

unread,
Jun 6, 2012, 9:13:56 PM6/6/12
to adsen...@googlegroups.com
Hi Sergio
 
My previous emails have said exactly which version of the client library the bug is in (Version 1.1 of the .Net Beta Client API Library) and exactly what the problem is. I've even told you the exact line of code where you can see the failure occuring in the .Net API sample and why it is occurring and how it can be fixed.
 
I'd be amazed if the .Net API Sample manages to get past line 52 in GenerateReport.cs.  Perhaps the AdSense accounts you are running against do not exercise this area of code, try setting a break point.
 
I've noticed that since I fetched the code in early May, there has been a new release of Version 1.1 of the .Net Beta Client API Library, but I can see it has exactly the same issue.
I'm not sure how it is possible for me to help you any further as I've given you every bit of information on the bug and how to fix it.
 
Cheers
 
Peter
 

 
To view this discussion on the web visit https://groups.google.com/d/msg/adsense-api/-/xk4Uzu_IMecJ.

To post to this group, send email to adsen...@googlegroups.com.
To unsubscribe from this group, send email to adsense-api...@googlegroups.com.

Sérgio Gomes

unread,
Jun 7, 2012, 5:00:05 AM6/7/12
to adsen...@googlegroups.com
Hi Peter,

Version 1.1 refers to the version of the AdSense Management API, as well as the associated service classes. These are simply the end classes that are generated to wrap an API in .NET, and don't include any transport code, which seems to be the bit that's failing.

The problem you're mentioning is in the dotnet library itself (google-api-dotnet-client), which uses a different numbering scheme, and is currently at 20120504-1.2.4507-beta (or 1.2.4507-beta in the download tarball). If you have an old version of this, that's very likely what's causing the issue, and why I can't replicate it in my install, where it runs normally.

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


---

Peter Diamant

unread,
Jun 7, 2012, 10:14:38 PM6/7/12
to adsen...@googlegroups.com
Hi Segio
 
Yep, those are the two dotnet library versions (4506 and 4507) I was talking about in my last email that both have the bug.
 
We might as well close this thread now as we appear to be going around in circles.
 
As I said before, my application works fine with my client library fixes, so I don't have any issues.
 
Cheers
 
Peter

To view this discussion on the web visit https://groups.google.com/d/msg/adsense-api/-/qeOho0vP46gJ.

To post to this group, send email to adsen...@googlegroups.com.
To unsubscribe from this group, send email to adsense-api...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages