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
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
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.
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
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
|
||||||