Search code examples
pythongoogle-oauthgoogle-ads-apigoogle-authentication

GoogleOAuth2 Auth Failure "unauthorized_client"/ Python GoogleAdWord API


Iam trying to accsess OAuth2 in Python (the code is the same as http://code.google.com/p/google-api-ads-python/source/browse/trunk/examples/adspygoogle/adwords/v201302/misc/use_oauth2.py?spec=svn139&r=139):

flow = OAuth2WebServerFlow(client_id='XXX',
      client_secret='YYY',          
      scope='https://adwords.google.com/api/adwords',
      user_agent='ZZZ')

authorize_url = flow.step1_get_authorize_url('urn:ietf:wg:oauth:2.0:oob')        

    code = raw_input('Code: ').strip()        
    credential = None
    try:
        credential = flow.step2_exchange(code) #<- error
    except FlowExchangeError, e:
        sys.exit('Authentication has failed: %s' % e)

This produces a "socket.error: [Errno 10054]" error at the step2_exchange and Python cuts off the excact message. So after checking the key with OAuthplayground (to get an better errormsg) i get this Error:

HTTP/1.1 400 Bad Request
Content-length: 37
X-xss-protection: 1; mode=block
X-content-type-options: nosniff
X-google-cache-control: remote-fetch
-content-encoding: gzip
Server: GSE
Via: HTTP/1.1 GWA
Pragma: no-cache
Cache-control: no-cache, no-store, max-age=0, must-revalidate
Date: Thu, 06 Jun 2013 13:54:29 GMT
X-frame-options: SAMEORIGIN
Content-type: application/json
Expires: Fri, 01 Jan 1990 00:00:00 GMT

{
  "error" : "unauthorized_client"
}

I checked that client_id (for installed Apps) and client_secret are Identical with the one specified in the Google API Console (https://code.google.com/apis/console/).

If i do the whole proces over OAuthPlayground it will work but if i try to use a Token created by playground the App fails also.

Anyone knows how to fix it?


Solution

  • Fixed it. Iam behind a proxy which makes lets the step1 Auth through but apparently not the step2 auth. So a simple

    h = httplib2.Http(proxy_info = httplib2.ProxyInfo PROXY DATA .....)
    flow.step2_exchange(code, h)
    

    fixed it.