Convert Google-Ads API GoogleAdsRow object to a dictionary or something useful to end up in a .CSV?

519 views
Skip to first unread message

James Nixon

unread,
Jan 17, 2020, 11:44:54 AM1/17/20
to AdWords API and Google Ads API Forum

Google Ads API, Their new version of the Google Adwords API returns data in an object called "GoogleAdsRow". I have not found any use at all for the native object. The information presented in this format is not usable and it is quite confusing. I want to print my file to a basic .csv format, but there is not any type of delimiter or iterable as far as i can tell. So far I have only been able to print each entire row as a single cell. Not Helpful :-).



My main function looks like this following. I have provided two examples of what I have tried with a comment block identifying both attempts:

def main(client, customer_id, page_size):
    ga_service = client.get_service('GoogleAdsService', version='v2')

    query = ('SELECT ad_group.id, ad_group_criterion.type, '
             'ad_group_criterion.criterion_id, '
             'ad_group_criterion.keyword.text, '
             'ad_group_criterion.keyword.match_type FROM ad_group_criterion '
             'WHERE ad_group_criterion.type = KEYWORD')

    results = ga_service.search(customer_id, query=query, page_size=page_size)

    try:
        with open(path, "w", encoding = "utf-8", newline = "") as f:
        #with open(path, "w") as csv:
            csv_writer = csv.writer(f, delimiter=',')
            for row in results:
                campaign = row.campaign           
                csv_writer.writerow([row]) #Prints entire returned row as a single cell
                csv_writer.writerow(row) #Tells me there is no delimiter


The iterable error is as follows


<ipython-input-15-e736ee2d05c9> in main(client, customer_id, page_size)
     17                 campaign = row.campaign
     18                 #csv_writer.writerow([row]) #Prints entire returned row as a single cell
---> 19                 csv_writer.writerow(row) #Tells me there is no delimiter
     20 
     21 

Error: iterable expected, not GoogleAdsRow

Google Ads API Forum Advisor Prod

unread,
Jan 17, 2020, 4:18:46 PM1/17/20
to jni...@condati.com, adwor...@googlegroups.com

Hello James,

With regards to your concern, if you are using our client libraries, it is not possible to retrieve the data in .csv format. However, as an alternative you could use the cURL operation to get the output in JSON format which can be further converted to csv by implementing the logic on your end. Please refer to this guide for more details on how to interact with Google Ads API using cURL. Please give this a try and let me know if you have any further questions.

Regards,
Nikisha Patel, Google Ads API Team



ref:_00D1U1174p._5001USwkbX:ref

James Nixon

unread,
Jan 20, 2020, 11:50:21 AM1/20/20
to Google Ads API Forum Advisor Prod, adwor...@googlegroups.com
The documentation states that using this method is not practical for real-world application.: 
image.png

Is there a way to convert the googleadsrow object to .csv using other logical methods?


--


This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.

Pete Lavetsky (AdWords API Guru)

unread,
Mar 2, 2020, 12:38:56 PM3/2/20
to AdWords API and Google Ads API Forum
James,

Look into the getAllFields method on the GeneratedMessageV3 object for each object returned within each GoogleAdsRow. Relatively straight forward exercise to map back to your query string.

Google Reps: A toCSV option would be greatly appreciated and make everyone's lives easier. Header row would be the query selects.

ie. select customer.id, customer.descriptive_name, customer.currency_code from customer would return a CSV like:

customer.id,customer.descriptive_name,customer.currency_code
1239871423,Cool Customer,USD
9122351424,Cooler Customer,CAD

Pete

Google Ads API Forum Advisor Prod

unread,
Mar 2, 2020, 3:21:19 PM3/2/20
to pete.l...@gmail.com, adwor...@googlegroups.com

Hello Pete,

Thank you for writing to us regarding your concern. I will update the existing feature request with your concerns to retrieve the data in .csv format via API. Please keep an eye on our blog post for future updates and announcements related to this and let us know if you have any additional concerns.



Regards,
Nikisha Patel, Google Ads API Team



ref:_00D1U1174p._5001USwkbX:ref

Google Ads API Forum Advisor Prod

unread,
Mar 3, 2020, 10:56:05 AM3/3/20
to pete.l...@gmail.com, adwor...@googlegroups.com

Hello,

I checked internally with our team for the feature request to retrieve the data in .csv format via API and found that this feature is not intended to be provided in future releases. You could use language-level utilities to create a CSV file, if necessary. Please let us know if you have any additional concerns.



Regards,
Nikisha Patel, Google Ads API Team



ref:_00D1U1174p._5001USwkbX:ref
Message has been deleted

Google Ads API Forum Advisor

unread,
Feb 21, 2022, 10:25:45 PM2/21/22
to poojitha...@gmail.com, adwor...@googlegroups.com
Hi Poojitha,

Thank you for reaching out.

Depending on the client library you are using, you may reach out to their respective client library owner via their Github's Issues tab for further guidance on code level issues and solutions, such as getting the googleadsrow into a json or a csv file. I hope this helps.

Best regards,

Google Logo
Peter Laurence
Google Ads API Team
 


ref:_00D1U1174p._5001USwkbX:ref
Reply all
Reply to author
Forward
0 new messages