I'm having trouble connecting to the Google Ads API with Python, first I have all the proper credentials for the connection which are DEVELOPER_TOKEN, CLIENT_SECRET, REFRESH_TOKEN, CUSTOMER_ID. It should be noted that I am trying to connect with the method that I have a yaml file where I have all my credentials and well I have tried to get a code where I can connect and I have tried all the methods and it does not let me, someone who can guide me for the API connection, please.

I have tried with the script of the repository of the same that Google Ads sends you, but it is very extensive to understand and in the same way I feel that I managed to understand it a little but nevertheless it does not work for me, I also tried with others and I don't need you to help me, please

Tag:google-ads-api, google-api, python

Only one comment.

  1. Johnover Board

    Totally understand the challenge with setting up Google Ads API python scripts. It took us a while as well - I'll try my best to go through what we've understood and put in place.

    You need client ID, client secret, refresh token, developer token and Manager account ID to get you an access token - which lasts for an hour. You can have them in a yaml file like this.

    developer_token: 'abc123' client_id: 'xxxxxx' client_secret: 'xxxxxx' refresh_token: 'xxxxxx' use_proto_plus: 'False'

    Have them imported to your python script. Every execution will create a new access token -

    client = GoogleAdsClient.load_from_storage("google-ads.yaml")

    Create a search object -

    ga_service = client.get_service("GoogleAdsService")

    Run your query -

    stream = ga_service.search_stream(customer_id=customer_id, query=query)

    Process the data you get back -

    for batch in stream_data: for row in batch.results: print(row)

    Hope this helps! Disclaimer - we are also figuring things out, if you know a better approach please let us know!

Add a new comment.