Batch processing with no User Interaction

116 views
Skip to first unread message

aimsm

unread,
Nov 29, 2011, 8:46:53 AM11/29/11
to Google Analytics Management API
I have a batch process that will be scheduled and run every day. On a
day to day basis - it must have no user interaction (via browser
pages) and needs to use the Management API version 3.0.

I realize OAuth 2.0 is the recommended authentication method - but how
do I use that with no user intervention on an ongoing basis? To be
clear, I know I have to register the app - I don't want to have to
have a manual process where somebody has to keep authorizing the user
access via a web page.

Please can you also tell me how to stop the "Captcha" processing from
occurring?

The "Data Export API" is fine - I can do everything I need with
"ClientLogin", it's the "Management API" that is causing us problems
in the batch world.

aimsm

unread,
Nov 30, 2011, 6:03:43 AM11/30/11
to google-analytic...@googlegroups.com
Does anyone know how to do this - this is critical to our project?

Chris Harrington

unread,
Nov 30, 2011, 12:43:31 PM11/30/11
to Google Analytics Management API
With OAuth 2.0 you will get a refresh token, which shouldn't expire.

aimsm

unread,
Nov 30, 2011, 1:04:08 PM11/30/11
to google-analytic...@googlegroups.com
Hi Chris, i've considered the refresh token (see below) but this still requires User Interaction. We would ideally not want to use a browser to consent at all. Is this possible?

In the meantime, I am working on a solution using the browser (in "DEVICE" mode) but it might not be feasible to use this due to the fact that we will have 50+ separate accounts to maintain (and logging onto a web browser to give consent for all of these would take forever).

I haven't got far enough into this code yet to see - i've got the user code and device code, i've consented via the website, and my code has successfully obtained the first access and refresh token. I'm hoping I can use the refresh token (when necessary) to get a new access token without ever having to give explicit (browser) consent again. Will GA OAuth2 allow me to do that i.e. consent once only via the browser and then never have to do this again (using the refresh token to get the new access token each time)  - this is what i'm hoping for? If this is possible then the "once only" login might be feasible however I would still need to do this over 50 times as i'll have to consent once for each account. If there is a danger that I might have to log on again to give explicit consent, e.g. if the batch jobs haven't run for a few days and google decide I need to give explicit consent again, then I can't follow this approach.

Many thanks for your help.

Zhao Jun

unread,
Dec 20, 2011, 1:57:07 AM12/20/11
to google-analytic...@googlegroups.com
With the new release, I think what you are hoping for is true now. Once user gives you consent, Google will not ask for user consent again. 

Go to change #3

I think refresh token does not require user intervention at all. If you are Google Python Library, it actually automatically refresh the access token when you authorize the http request. 

    # The closure that will replace 'httplib2.Http.request'.
    def new_request(uri, method='GET', body=None, headers=None,
                    redirections=httplib2.DEFAULT_MAX_REDIRECTS,
                    connection_type=None):
      if not self.access_token:
        logger.info('Attempting refresh to obtain initial access_token')
        self._refresh(request_orig)

Jimmy

unread,
Aug 26, 2012, 11:47:05 AM8/26/12
to google-analytic...@googlegroups.com
Hello,

 Did you successfully do what you want ? I would like to create a batch that gets analytics data every night, and i don t know how to add an automatic login.

Jimmy

Chris Harrington

unread,
Aug 27, 2012, 12:43:13 PM8/27/12
to google-analytic...@googlegroups.com
With OAuth you don't login - you authenticate.
Reply all
Reply to author
Forward
0 new messages