Hi Deny,

that's an interesting solution. I've never thought about handle the 
response that way but I'll definitely check it out, thx.

Regarding the encoding, I've had troubles too, but fixed them with this 
line below the #!/bin/bash:

#coding=utf-8

Don't know if that helps in your case, though.

Regards
Mat
[email protected] schrieb am Mittwoch, 30. September 2020 um 14:06:09 
UTC+2:

> Exactly Mat, that's what drove me nuts and made me have to come up with a 
> (much) less than elegant solution because I really can't afford to write 
> non-reusable code at this point in my life for a matter of principle. I'll 
> share the snippet below, can't guarantee it will work without modifications 
> for any given resultset but it has been working flawlessly for me so far:
>
> import yaml
> import codecs
>
> # your loop goes here (for row in ...)
>    tmp_row = str(row).replace(" {", ":").replace("}", "").replace('\\"', 
> "")
>    tmp_row = codecs.escape_decode(tmp_row)[0]
>    tmp_row = tmp_row.decode("utf-8")
>    new_row = yaml.load(tmp_row, Loader=yaml.FullLoader)
>
> # Note: had to also use a codecs function to fix encoding which is messed 
> up as well.
>
> On Wednesday, September 30, 2020 at 3:35:05 AM UTC-3 Mat wrote:
>
>> Hi Deny,
>>
>> I feel with you. The Google Ads API documentation seems to be written by 
>> a mean bot.
>>
>> Using the Python library, you can fetch reports like this:
>>
>> ###
>> VERSION = 'v5'
>> ga_service = google_ads_client.get_service('GoogleAdsService', 
>> version=VERSION)
>> query = ('SELECT '
>>           'campaign.id, '
>>           'campaign.name, '
>>           'ad_group.id, '
>>           'ad_group.name, '              
>>           'FROM ad_group '
>>           )    
>> response = ga_service.search_stream(str(customer_id), query=query)
>> for batch in response:
>> for row in batch.results:    
>> campaign = row.campaign
>> ad_group = row.ad_group
>> campaign_id = campaign.id.value
>> campaign_name = campaign.name.value
>> ad_group_id = ad_group.id.value
>> ad_group_name = ad_group.name.value      
>> ###
>>
>> If the value is an emum 
>> <https://developers.google.com/google-ads/api/reference/rpc/v5/CriterionTypeEnum.CriterionType>,
>>  
>> you can handle it like this:
>>
>> ###
>> ad_group_criterion_type_enum = google_ads_client.get_type( 
>> 'CriterionTypeEnum', version=VERSION).CriterionType
>> criterion_type = 
>> ad_group_criterion_type_enum.Name(ad_group_criterion.type)
>> ###
>>
>> Regards
>> Mat
>>
>> [email protected] schrieb am Montag, 28. September 2020 um 14:19:30 
>> UTC+2:
>>
>>> Hi Ben,
>>>
>>>  
>>>
>>> I’m using the python library and was very disappointed to find out that 
>>> the results from the API queries are delivered as objects which are 
>>> non-iterable, making the use of data dictionaries a lot more difficult and 
>>> a lot less elegant.
>>>
>>>  
>>>
>>> Other Google APIs present results as dictionaries which can be inspected 
>>> for content (fields and values) according to the same data dictionary that 
>>> was used for the request. That makes configuring API extractions easy to 
>>> build, maintain and improve, using code such as:
>>>
>>>  
>>>
>>> for element in my_api_dict:
>>>
>>>   if element[“id”] in returned_values:
>>>
>>>     results.append(returned_values[element[“id”]]
>>>
>>>  
>>>
>>> On the other hand, the new Google Ads API (which should supposedly be 
>>> better than previous ones?) demands that the result set elements are named 
>>> explicitly, like:
>>>
>>> results = [returned_values.table1.column1,
>>>
>>>   returned_values.table1.column2,
>>>
>>>   returned_values.table1.column3, …
>>>
>>> ]
>>>
>>>  
>>>
>>> I feel very dirty to admit I came up with a fugly and shameful solution 
>>> which is converting the results to string and then making some 
>>> modifications to turn it into a yaml string and parse it, so I could 
>>> transform it into a dictionary. Ugly solutions make me extremely 
>>> uncomfortable and frustrated, and I don’t think I should have to do things 
>>> like this in 2020, **especially** dealing with an API developed by the 
>>> almighty Google.
>>>
>>>  
>>>
>>> I can live with the ugly solution if you can live with my deep 
>>> disappointment in your company development teams.
>>>
>>>  
>>>
>>> Cheers,
>>>
>>> Deny
>>>
>>>  
>>>
>>> *From:* Google Ads API Forum Advisor Prod <[email protected]> 
>>> *Sent:* Friday, September 25, 2020 5:39 PM
>>> *To:* Watanabe, Deny (SPL-MEW) <[email protected]>
>>> *Cc:* [email protected]
>>> *Subject:* [EXTERNAL] RE: GoogleAdsRow object not iterable?
>>>
>>>  
>>>
>>> Hi Deny,
>>>
>>> Thanks for the post, and sorry that you're having an issue here.
>>>
>>> Can you share a little more detail about the problem you're having? I 
>>> might be able to help you get around the issue, and if not can help post a 
>>> feature request so that we can fix it in the future.
>>>
>>> It seems like you might be having an issue with one of the client 
>>> libraries. Can you let me know which language you're using?
>>>
>>> Thanks!
>>> Ben Karl, Google Ads API Team
>>>
>>>
>>>
>>> ref:_00D1U1174p._5004Q25Wv5e:ref
>>> This message contains information which may be confidential and 
>>> privileged. Unless you are the intended recipient (or authorized to receive 
>>> this message for the intended recipient), you may not use, copy, 
>>> disseminate or disclose to anyone the message or any information contained 
>>> in the message. If you have received the message in error, please advise 
>>> the sender by reply e-mail, and delete the message. Thank you very much.
>>>
>>

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"AdWords API and Google Ads API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/287ccda2-91c7-4165-82cb-3e753082f11dn%40googlegroups.com.

Reply via email to