Re: How to convert Google-Ads API GoogleAdsRow to json?

2021-05-18 Thread rahul...@decision-tree.com
I have found a working solution. This will go something like this:
```
import proto 
response = ga_service.search_stream(search_request) 
for batch in response: 
  for row in batch.results: 
   logging.debug(proto.Message.to_dict(row))
```
On Tuesday, September 8, 2020 at 6:33:16 PM UTC+5:30 kol...@exito.de wrote:

> We are using the Python client library because we don't want to write all 
> the basic stuff.
>
> In the meantime I found out how you can directly convert the API result to 
> a pandas dataframe in Python:
>
> from pandas import json_normalize
> from google.protobuf.json_format import MessageToJson
> ...
>
> results_report = ga_service.search(account_id, query=query_report, 
> page_size=_DEFAULT_PAGE_SIZE)
>
> list_all_rows = []
>
> for row in results_report:  
> serialized_json = MessageToJson(row).replace('\n', '')
> serialized_json_dict = json.loads(serialized_json)
> 
> df_row = json_normalize(serialized_json_dict)  
> list_all_rows.append(df_row)
>
> if len(list_all_rows) == 0:
> continue
>
> df_all_rows = pd.concat(list_all_rows)
>
>
> This works fine in Ads API v4 and v5. The same code works for 5 or 50 
> columns.
> TBH: I can't understand why you don't provide such a compact 
> transformation from the API result to a dataframe in your library examples.
>
> Who wants to retrieve every single field like this (taken from the 
> examples)?  That's awkward and tedious  ;-)
>
> for row in results:
>  ad_group = row.ad_group
>  ad_group_criterion = row.ad_group_criterion
>  keyword = row.ad_group_criterion.keyword  
>  ... 
>
> adsapiforumadvisor schrieb am Montag, 20. Juli 2020 um 15:30:55 UTC+2:
>
>> Hi Thomas,
>>
>> Thank you for reaching out. I just want to confirm that you're following 
>> this 
>> example 
>>  
>> when making the cURL request to get the JSON response. If so, please share 
>> your client customer ID, cURL request, and any additional error details *via 
>> Reply privately to author *so I can further investigate the issue.
>>
>> Regards,
>> Mitchell
>>
>> Google Ads API Team
>>
>> ref:_00D1U1174p._5004Q21msBS:ref
>>
>

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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 adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
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 adwords-api+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/1d5d1d31-a39c-41be-9685-6c0b9e3a3de1n%40googlegroups.com.


Re: How to convert Google-Ads API GoogleAdsRow to json?

2020-09-08 Thread kol...@exito.de
We are using the Python client library because we don't want to write all 
the basic stuff.

In the meantime I found out how you can directly convert the API result to 
a pandas dataframe in Python:

from pandas import json_normalize
from google.protobuf.json_format import MessageToJson
...

results_report = ga_service.search(account_id, query=query_report, 
page_size=_DEFAULT_PAGE_SIZE)

list_all_rows = []

for row in results_report:  
serialized_json = MessageToJson(row).replace('\n', '')
serialized_json_dict = json.loads(serialized_json)

df_row = json_normalize(serialized_json_dict)  
list_all_rows.append(df_row)

if len(list_all_rows) == 0:
continue

df_all_rows = pd.concat(list_all_rows)


This works fine in Ads API v4 and v5. The same code works for 5 or 50 
columns.
TBH: I can't understand why you don't provide such a compact transformation 
from the API result to a dataframe in your library examples.

Who wants to retrieve every single field like this (taken from the 
examples)?  That's awkward and tedious  ;-)

for row in results:
 ad_group = row.ad_group
 ad_group_criterion = row.ad_group_criterion
 keyword = row.ad_group_criterion.keyword  
 ... 

adsapiforumadvisor schrieb am Montag, 20. Juli 2020 um 15:30:55 UTC+2:

> Hi Thomas,
>
> Thank you for reaching out. I just want to confirm that you're following this 
> example 
>  
> when making the cURL request to get the JSON response. If so, please share 
> your client customer ID, cURL request, and any additional error details *via 
> Reply privately to author *so I can further investigate the issue.
>
> Regards,
> Mitchell
>
> Google Ads API Team
>
> ref:_00D1U1174p._5004Q21msBS:ref
>

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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 adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
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 adwords-api+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/5bf43a6c-fc5b-45d6-a315-b5b8c62b6d00n%40googlegroups.com.


Re: How to convert Google-Ads API GoogleAdsRow to json?

2020-07-22 Thread Michael Birk
Hi Rahul,

I was able to use this Python library to convert the Ads API v3 responses 
to JSON:

   https://github.com/tigrus/protobuf-to-dict

mcb

On Tuesday, June 11, 2019 at 3:54:07 AM UTC-7 rahul...@gmail.com wrote:

> Hi Sai,
>
> I think Alexander is asking about the SDK. I am also facing the same 
> problem. If someone is using the python SDK for google ads API, how can one 
> convert the GoogleAdsRow to json. I have tried to use a CustomEncoder by 
> subclassing the json.JSONEncoder, but that is not the correct way as I will 
> never be sure if there is any particular data type that I am missing. Is 
> there a method like toJson() for this?
>
> Thanks,
> Rahul
>

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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 adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
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 adwords-api+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/4e6fd65d-7948-431c-9bbd-3da6afbe4f53n%40googlegroups.com.


RE: How to convert Google-Ads API GoogleAdsRow to json?

2020-07-20 Thread Google Ads API Forum Advisor Prod
Hi Thomas,

Thank you for reaching out. I just want to confirm that you're following this 
example when making the cURL request to get the JSON response. If so, please 
share your client customer ID, cURL request, and any additional error details 
via Reply privately to author so I can further investigate the issue.

Regards,
Mitchell
Google Ads API Team
ref:_00D1U1174p._5004Q21msBS:ref

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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 adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
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 adwords-api+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/tWJYU0QDRS6X00K8rU770rSS-HMmQBDrYMkQ%40sfdc.net.


Re: How to convert Google-Ads API GoogleAdsRow to json?

2020-07-17 Thread Thomas Koller
Unfortunately doesn't work in Ads API v4 (beta):

TypeError: Object of type GoogleAdsRow is not JSON serializable


Am Dienstag, 3. Dezember 2019 16:14:26 UTC+1 schrieb Mark Edmondson:
>
> I couldn't get the protobuf to work but using the SOAP seralizer zeep this 
> seems to work:
> https://python-zeep.readthedocs.io/en/latest/helpers.html
>
> from zeep import helpers
>
> def toJSON(x):
> input_dict = helpers.serialize_object(x)
> return json.dumps(input_dict)
>
>
>
>
> On Monday, April 1, 2019 at 9:12:38 PM UTC+2, Alexander Belozerov wrote:
>>
>> Hello there,
>> Im querying google ads api and need to save results as json. What is the 
>> best way to convert GoogleAdsRow type into json?
>>
>>
>> The result of the google ads api call is GoogleAdsRow that looks like 
>> this:
>>
>> campaign {
>>   resource_name: "customers/321/campaigns/123"
>>   id {
>> value: 123
>>   }
>>   name {
>> value: "Campaign Name A"
>>   }
>> }
>> metrics {
>>   clicks {
>> value: 711
>>   }
>>   impressions {
>> value: 2662
>>   }
>> }
>> segments {
>>   device: DESKTOP
>>   ad_network_type: SEARCH
>>   date {
>> value: "2019-03-01"
>>   }
>> }
>>
>> Instead of campaign, it can be adgroup, keywords, etc.
>> What is the best way to convert this kind of data to json?
>>
>

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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 adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
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 adwords-api+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/a47fe08e-ac6c-4a8c-932b-7429507bca6co%40googlegroups.com.


RE: How to convert Google-Ads API GoogleAdsRow to json?

2019-12-04 Thread Google Ads API Forum Advisor Prod
Hello,

Thank you for reaching out. If you are using the our client libraries, it is 
not possible to retrieve the data in JSON format. However, as an alternative 
you can use the cURL operation to get the output in JSON format. You can 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._5001UODiuH:ref

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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 adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
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 adwords-api+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/TP3qM0Q1ZZWV00sB3rH1yMRuy7cT269_JjVw%40sfdc.net.


Re: How to convert Google-Ads API GoogleAdsRow to json?

2019-12-03 Thread Mark Edmondson
I couldn't get the protobuf to work but using the SOAP seralizer zeep this 
seems to work:
https://python-zeep.readthedocs.io/en/latest/helpers.html

from zeep import helpers

def toJSON(x):
input_dict = helpers.serialize_object(x)
return json.dumps(input_dict)




On Monday, April 1, 2019 at 9:12:38 PM UTC+2, Alexander Belozerov wrote:
>
> Hello there,
> Im querying google ads api and need to save results as json. What is the 
> best way to convert GoogleAdsRow type into json?
>
>
> The result of the google ads api call is GoogleAdsRow that looks like this:
>
> campaign {
>   resource_name: "customers/321/campaigns/123"
>   id {
> value: 123
>   }
>   name {
> value: "Campaign Name A"
>   }
> }
> metrics {
>   clicks {
> value: 711
>   }
>   impressions {
> value: 2662
>   }
> }
> segments {
>   device: DESKTOP
>   ad_network_type: SEARCH
>   date {
> value: "2019-03-01"
>   }
> }
>
> Instead of campaign, it can be adgroup, keywords, etc.
> What is the best way to convert this kind of data to json?
>

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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 adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
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 adwords-api+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/a5a198c4-cf41-4db7-9271-1d15199443fb%40googlegroups.com.


Re: How to convert Google-Ads API GoogleAdsRow to json?

2019-06-12 Thread 'UK Analytics' via AdWords API and Google Ads API Forum
You need to use the Google protobuf library:
https://developers.google.com/protocol-buffers/docs/reference/python/

from google.protobuf import json_format

### code to get the object ###

rec_obj = row.recommendation.text_ad_recommendation.ad
json_str = json_format.MessageToJson(rec_obj) 
print(json_str)


Adam

On Tuesday, June 11, 2019 at 11:54:07 AM UTC+1, Rahul Kumar wrote:
>
> Hi Sai,
>
> I think Alexander is asking about the SDK. I am also facing the same 
> problem. If someone is using the python SDK for google ads API, how can one 
> convert the GoogleAdsRow to json. I have tried to use a CustomEncoder by 
> subclassing the json.JSONEncoder, but that is not the correct way as I will 
> never be sure if there is any particular data type that I am missing. Is 
> there a method like toJson() for this?
>
> Thanks,
> Rahul
>

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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 adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
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 adwords-api+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/88e93dbb-09d7-41b2-912a-6ecab2098b6e%40googlegroups.com.


RE: How to convert Google-Ads API GoogleAdsRow to json?

2019-06-11 Thread Google Ads API Forum Advisor Prod
Hello Rahul,

We don't have such functionality to get JSON format directly via GoogleAdsRow. 
Hence, I provided the CURL operation which will give JSON as output. I 
recommend you to post your concern on the client library issue tracker , Our 
client library owners are better equipped to answer this.

Regards,
Sai Teja, Google Ads API Team
ref:_00D1U1174p._5001UBmf8H:ref

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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 adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
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 adwords-api+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/rjSfR0PSY9YM00mH9uESSGQTi-i5K7TzNu_A%40sfdc.net.


Re: How to convert Google-Ads API GoogleAdsRow to json?

2019-06-11 Thread Rahul Kumar
Hi Sai,

I think Alexander is asking about the SDK. I am also facing the same 
problem. If someone is using the python SDK for google ads API, how can one 
convert the GoogleAdsRow to json. I have tried to use a CustomEncoder by 
subclassing the json.JSONEncoder, but that is not the correct way as I will 
never be sure if there is any particular data type that I am missing. Is 
there a method like toJson() for this?

Thanks,
Rahul

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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 adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
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 adwords-api+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/52055046-600a-45db-8027-7484cd233790%40googlegroups.com.


RE: How to convert Google-Ads API GoogleAdsRow to json?

2019-04-01 Thread googleadsapi-forumadvisor via AdWords API and Google Ads API Forum


Hello Alexander,

You can refer this APi call example mentioned here
,
which will give the response in JSON format, when you make API call using
CURL operations. For example you could try the below CURL operation to get
details of a campaign.

*CURL example to get Campaigns:*

curl -H "Authorization: Bearer YOUR_ACCESS_TOKEN"  -H "developer-token:
DEVELOPER_TOKEN"  -H "Content-Type: application/json"
https://googleads.googleapis.com/v1/customers//googleAds:search
--data '{query: "SELECT campaign.id, campaign.name FROM campaign ORDER
BY campaign.id"}'

Please let me know if you have any further questions.

Regards,
Sai Teja, Google Ads API Team


=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
https://ads-developers.googleblog.com/search/label/google_ads_api
https://developers.google.com/adwords/api/community/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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 adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
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 adwords-api+unsubscr...@googlegroups.com.
Visit this group at https://groups.google.com/group/adwords-api.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/1a0l0h008ovi80001f1ftcw6smjachk6ko30c1g68r34chj%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.