Miminal Python Example

567 views
Skip to first unread message

aydogan...@gmail.com

unread,
Jul 7, 2015, 1:26:46 PM7/7/15
to adwor...@googlegroups.com
Hello Everyone!

I am very new with AdWords API and trying to execute very basic example from the library.

I just filled   developer_token, user_agent, client_idclient_secret and refresh_token fields in googleads.yaml file and put it in my home directory.

When I run that example script, I get the following error:

Traceback (most recent call last):

  File "get_campaigns.py", line 81, in <module>

    main(adwords_client)

  File "get_campaigns.py", line 58, in main

    print campaign_service.get(selector)

  File "build/bdist.macosx-10.10-intel/egg/googleads/common.py", line 294, in MakeSoapRequest

  File "build/bdist.macosx-10.10-intel/egg/googleads/adwords.py", line 335, in SetHeaders

  File "build/bdist.macosx-10.10-intel/egg/googleads/oauth2.py", line 150, in CreateHttpHeader

  File "build/bdist.macosx-10.10-intel/egg/googleads/oauth2.py", line 166, in Refresh

  File "/Library/Python/2.7/site-packages/oauth2client-1.4.11-py2.7.egg/oauth2client/client.py", line 598, in refresh

  File "/Library/Python/2.7/site-packages/oauth2client-1.4.11-py2.7.egg/oauth2client/client.py", line 769, in _refresh

  File "/Library/Python/2.7/site-packages/oauth2client-1.4.11-py2.7.egg/oauth2client/client.py", line 834, in _do_refresh_request

oauth2client.client.AccessTokenRefreshError: invalid_grant


Any suggestion of your to fix that error is welcome.

Umesh Dengale

unread,
Jul 7, 2015, 9:45:57 PM7/7/15
to adwor...@googlegroups.com, aydogan...@gmail.com
Hello,

Please regenerate refresh token, update the refresh_token property in the googleads.yaml file and execute any example from the library.

Thanks,
Umesh, AdWords API Team.

Lukáš Vožda

unread,
Aug 31, 2015, 6:48:54 PM8/31/15
to AdWords API Forum, aydogan...@gmail.com
Hello,

ive got similar error. I regenerated refresh token many times, it didnt help, is there anything else i can do?

I spent hours trying to work it out but still the same result....

This is my error:
Traceback (most recent call last):
  File "./adwords.py", line 4, in <module>
    client = AdWordsClient.LoadFromStorage()
  File "/usr/local/lib/python3.4/site-packages/googleads/adwords.py", line 188, in LoadFromStorage
    cls._OPTIONAL_INIT_VALUES))
  File "/usr/local/lib/python3.4/site-packages/googleads/adwords.py", line 223, in __init__
    self.oauth2_client.Refresh()
  File "/usr/local/lib/python3.4/site-packages/googleads/oauth2.py", line 165, in Refresh
    self.disable_ssl_certificate_validation)))
  File "/usr/local/lib/python3.4/site-packages/oauth2client/client.py", line 597, in refresh
    self._refresh(http.request)
  File "/usr/local/lib/python3.4/site-packages/oauth2client/client.py", line 768, in _refresh
    self._do_refresh_request(http_request)
  File "/usr/local/lib/python3.4/site-packages/oauth2client/client.py", line 833, in _do_refresh_request
    raise AccessTokenRefreshError(error_msg)
oauth2client.client.AccessTokenRefreshError: invalid_grant


Thank you.
Lukas.

Thanet Knack Praneenararat (AdWords API Team)

unread,
Sep 1, 2015, 7:05:57 AM9/1/15
to AdWords API Forum, aydogan...@gmail.com
Hello,

Can you try following this guide again?
Make sure you select a correct type of application type, log in as your MCC account user when you do the step to get refresh token, and finally leave no spaces after a refresh token in googleads.yaml.

Best,
Thanet, AdWords API Team

Lukáš Vožda

unread,
Sep 3, 2015, 1:48:41 PM9/3/15
to AdWords API Forum, aydogan...@gmail.com
Hello,

thank you for your reply. I tried do it again according to the guide you sent. Result is still the same :-(

I even tried even this but there is not AdWords in the list of APIs to autorize and this but got the same invalid_grant error.

I really dont know where is the problem, I will try to describe my process step by step:

1. I got the developer token approved in my MCC account
2. Then created project in Google Developers Console and added OAuth 2.0 client ID (application type - other), So i got client_id and client_secret
3. Then executed this, put the link to the browser, again under my MCC account accepted and got the code into the terminal, which gave me my refresh token
4. After these steps i had all the information to fill googleads.yaml file, stored in my home directory, there are no spaces after token strings
5. I executed these two lines in python: 
from googleads.adwords import AdWordsClient
client = AdWordsClient.LoadFromStorage()

I tried many times and still getting invalid_grant error.

If you find where is the problem, I would be very grateful.

Thank you.

Lukas

Thanet Knack Praneenararat (AdWords API Team)

unread,
Sep 3, 2015, 2:19:42 PM9/3/15
to AdWords API Forum, aydogan...@gmail.com
Hello,

Could you try two more things again?
  1. Your application type in the step 2 is installed application, not web application.
  2. After putting information in googleads.yaml, can you just run get_campaigns example as is?
Thanks,
Thanet, AdWords API Team

Lukáš Vožda

unread,
Sep 3, 2015, 3:22:12 PM9/3/15
to AdWords API Forum, aydogan...@gmail.com
Thank you again for you reply, Thanet.

The thing is that there is not an option in step 2 to choose between installed or web application as the manual says. There are just application types:

I have chosen option "Other".


Yes i run get_campaigns as is and got the same error:


Is there any possibility I can share with you my files to test it as you are an API team member?


Thanks again for helping.


Lukas

Thanet Knack Praneenararat (AdWords API Team)

unread,
Sep 3, 2015, 5:59:09 PM9/3/15
to AdWords API Forum, aydogan...@gmail.com
Hi,

Please reply to me privately by clicking Reply privately to author icon on the top right of my reply:
  • Your googleads.yaml (be sure to strip some part of your credential info, e.g., removing some 4-5 characters in the middle of refresh tokens, client id, etc)
  • SOAP logs and error logs in text
  • Your account ID (both MCC and child account) and MCC email address
I need to escalate this to a person more familiar with the python client lib.

While you are waiting, could you please try creating a new refresh token again? This time, use OAuth2 Playground. Again, make sure you are logged in as your MCC account for all steps.

Thanks,
Thanet, AdWords API Team

Foluso Ogunlana

unread,
Oct 14, 2015, 5:51:07 PM10/14/15
to AdWords API Forum
Hi Everyone, 

I've had this exact same problem and I solved it by including the path to googleads.yaml as an argument to LoadFromStorage.

adwords.AdWordsClient.LoadFromStorage('PATH_TO_GOOGLEADS.YAML')

Thanks
Reply all
Reply to author
Forward
0 new messages