2

Just getting started on the Adwords API, for some reason I can't seem to connect at all.

The code below, straight from the tutorial throws the error:

Traceback (most recent call last):
  File "<pyshell#12>", line 1, in <module>
    client = AdWordsClient(path=os.path.join('Users', 'ravinthambapillai', 'Google Drive', 'client_secrets.json'))
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/adspygoogle/adwords/AdWordsClient.py", line 151, in __init__
    self._headers = self.__LoadAuthCredentials()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/adspygoogle/adwords/AdWordsClient.py", line 223, in __LoadAuthCredentials
    return super(AdWordsClient, self)._LoadAuthCredentials()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/adspygoogle/common/Client.py", line 94, in _LoadAuthCredentials
    raise ValidationError(msg)
**ValidationError: Authentication data is missing.**

from adspygoogle.adwords.AdWordsClient import AdWordsClient
from adspygoogle.common import Utils
client = AdWordsClient(path=os.path.join('Users', 'this-user', 'this-folder', 'client_secrets.json'))

2 Answers 2

2

It looks like there's two issues. First, try removing the last path element, as far as I recall, the path parameter expects a directory that contains the authentication pickle, logs etc. This approach requires that you already have a valid auth_token.pkl.

Second, it appears that you're using OAuth2 for authentication (I'm guessing by the client_secrets.json file). For this to work, you'll need to use the oauth2client library and provide an oauth2credentials instance in the headers parameter to AdWordsClient.

The following is straight from the file examples/adspygoogle/adwords/v201302/misc/use_oauth2.py in the client distribution and should give you an idea how it works:

# We're using the oauth2client library:
# http://code.google.com/p/google-api-python-client/downloads/list
flow = OAuth2WebServerFlow(
  client_id=oauth2_client_id,
  client_secret=oauth2_client_secret,
  # Scope is the server address with '/api/adwords' appended.
  scope='https://adwords.google.com/api/adwords',
  user_agent='oauth2 code example')

# Get the authorization URL to direct the user to.
authorize_url = flow.step1_get_authorize_url()

print ('Log in to your AdWords account and open the following URL: \n%s\n' %
     authorize_url)
print 'After approving the token enter the verification code (if specified).'
code = raw_input('Code: ').strip()

credential = None
try:
credential = flow.step2_exchange(code)
except FlowExchangeError, e:
sys.exit('Authentication has failed: %s' % e)

# Create the AdWordsUser and set the OAuth2 credentials.
client = AdWordsClient(headers={
  'developerToken': '%s++USD' % email,
  'clientCustomerId': client_customer_id,
  'userAgent': 'OAuth2 Example',
  'oauth2credentials': credential
})
Sign up to request clarification or add additional context in comments.

2 Comments

dorian: here the client_customer_id is a variable. Is this value supposed to be provided by the customer, or is it considered a confidential value?
'client_customer_id' is just the ID of the Google AdWords account that you want to access ("123-456-7890"). AFAIR it's possible to omit this parameter, in which case you'll access the top-level Adwords account connected to your Google account.
1

I am not familiar with the AdWordsClient api but are you sure your path is correct?

your current join produces a relative path, do you need an absolute one?

>>> import os
>>> os.path.join('Users', 'this-user')
'Users/this-user'

For testing you could hardcode the absoulte path in to make sure it is not a path issue

I would also make sure that 'client_secrets.json exists, and that it is readable by the user executing python

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.