Since launching the AdSense Management API in October last year, we’ve received a number of questions and feedback from you while coding your applications. Today, we’ll address the most frequently asked questions and share some best practices.
How do I authenticate? Do I need to use OAuth?
Right now, the only authentication method we support is OAuth, but don’t let that intimidate you; OAuth 2.0 supports several authentication methods, for web server, client-side and installed applications and devices, which together cover all use cases.
You can find more information on how to authenticate in your favourite client library language in our client library guide or the more generic OAuth 2.0 documentation .
How do I stop my users from having to authorize my application every time they use it?
If you don’t take steps to store your users’ authentication data or set the appropriate flags on your request, the authentication process will run them through a permission-granting dialog similar to the one below every time:
In order to avoid this and improve the experience for users of your web or installed application, you should store their authentication data.
There are two types of token that we need to know about here: access tokens and refresh tokens . Access tokens give you immediate access to a user’s data, and are short-lived, whereas refresh tokens are long-lived, allowing you to generate new access tokens when you need them, even if the user isn’t present.
For installed or web applications we recommend storing both, and using the refresh token to generate a new access token whenever the one you stored expires.
For client-side applications, things should be a little easier, as all it should take is a redirect. The OAuth 2.0 documentation for client-side applications has all the information you need.
For more information on request tokens, you can check the relevant section in the OAuth 2.0 documentation , or the “Persisting authentication data” section in our client library guide if you’re using one of the client libraries.
How often can I run my report queries?
Every application has different needs, so the answer to this question will no doubt depend on what you’re doing. There are, however, a few guidelines we can give you.
First of all, try to collect data on the same frequency that you analyze it. That is, if you’re interested in daily performance, there’s no need for you to collect data more often than once a day, as our reporting can compile that data for you.
On the other hand, if you’re trying to get data as frequently as possible, bear in mind that we cache our report data for 60 seconds. There’s thus no point in running the same report more often than once a minute; the data you get won’t be any fresher, and you’ll just be wasting your request quota.
How do I get my performance data per country / domain?
Most reports are based on a time dimension such as DATE , WEEK or MONTH , which is to say that they’re grouped by that particular dimension.
Not all reports need to be based on a time dimension, however. In fact, a very useful report for those of you with many international visitors is to get a breakdown of visitors per country. In order to get that, just set your start and end dates and choose COUNTRY_CODE or COUNTRY_NAME as the dimension.
You can combine both approaches as well, to get a breakdown per country for every month, for example.
To get some more background on reports and the concepts behind them, check out our Diving into Reports blog post .
What should I do if my question isn’t answered here?
We’ve got a whole bunch of resources for you, from the reference documentation to our client library guide and code examples for several programming languages .
If that doesn’t help, take a look in our forum , and you might find a similar question or get a chance to post your own. You can also join us in a Hangout during our regular office hours . We’ll be around to give you a hand in either case!
- Sérgio Gomes , AdSense API Team