Hi,
We had setup a report for region level campaign metrics. After migrating 
from v6 to v8, we are having troubles in fetching the data from the 
services mentioned in subject.
I want to fetch city names & country names from geoTargetConstant 
(Criterion ID). But in most of the documents, vice-versa is explained (for 
ex: 
https://developers.google.com/google-ads/api/docs/samples/get-geo-target-constant-by-name)

Explaining 2 step procedure to show the process I used to follow (kindly 
note, I am doing this in Python3) & therefore, the point of problem:

   1. Query to get the daily report data:
   
   SELECT campaign.id, campaign.name, campaign.status,
   segments.date, segments.day_of_week, segments.ad_network_type, 
   segments.device, metrics.clicks, metrics.impressions, metrics.cost_micros,
   metrics.conversions, metrics.conversions_value, metrics.ctr, 
   metrics.interactions,
   metrics.video_views, metrics.video_view_rate,
   segments.geo_target_city, geographic_view.country_criterion_id
   FROM geographic_view
   WHERE campaign.status in('ENABLED', 'PAUSED')
   AND segments.date BETWEEN '{start_dt}' AND '{end_dt}'
   
   2. segments.geo_target_city & geographic_view.country_criterion_id gives 
   out ids but not names. To fetch the names corresponding to these ids, I had 
   introduced this function:
   
   








*def get_city_and_country_names(google_source, ads_client):     df_orig = 
   pd.DataFrame(google_source)     #df_orig has data from the main report     
   df_orig['country_id'] = 'geoTargetConstants/' + 
   df_orig['country_id'].astype(str)     gtc_service = 
   ads_client.get_service("GeoTargetConstantService", version="v6")     
   location_names = 
   ads_client.get_type( 
"SuggestGeoTargetConstantsRequest",version="v6").GeoTargets() 
       location_names.geo_target_constants.extend(df_orig['city_id'].unique()) 
       results = 
   gtc_service.suggest_geo_target_constants(geo_targets=location_names)     
   cities = {}     countries = {}*
   
   

*    for suggestion in results.geo_target_constant_suggestions:         
   geo_target_constant = suggestion.geo_target_constant         
   cities[geo_target_constant.resource_name] = geo_target_constant.name*
   
   






*        for geo_target_constant_parents in 
   suggestion.geo_target_constant_parents:             if 
   geo_target_constant_parents.target_type == "Country":                 
   countries[geo_target_constant_parents.resource_name] = 
   geo_target_constant_parents.name     df_city = 
   pd.DataFrame(cities.items(),columns=['city_id', 'city'])     df_country = 
   pd.DataFrame(countries.items(),columns=['country_id', 'country'])     df = 
   df_orig.merge(df_city, how='left', on=['city_id']).merge(df_country, 
   how='left', on=['country_id'])     return df*
   But in v8, there are significant challenges.
   One is:
   
*error_code: geo_target_constant_suggestion_error: LOCATION_NAME_LIMIT 
   message: "At most 25 location names can be specified in a 
   SuggestGeoTargetConstants method."*
   So, you can't really execute the command to fetch city names all at 
   once, you will have to break df into 25 rows...
   
   Second is, when I execute the function to do the similar job (after 
   taking care of the location_name_limit error),  I get this error:
   *TypeError: suggest_geo_target_constants() got an unexpected keyword 
   argument 'geo_targets'*
   or
   *Invalid constructor input for SuggestGeoTargetConstantsRequest: 
   geo_target_constants: "geoTargetConstants/1007740"*
   From this error, it looks like that the geoTargetConstants to Name data 
   can't be mapped anymore.
   
   Modified function I have been using:
   
   
*def chunker(seq, size):     return (seq[pos:pos + size] for pos in 
   range(0, len(seq), size))*
   
   

































*def get_city_and_country_names(google_source, ads_client):     df_orig = 
   pd.DataFrame(google_source)     #df_orig has data from the main report     
   df_orig['country_id'] = 'geoTargetConstants/' + 
   df_orig['country_id'].astype(str)     
   df_unique=df_orig[['city_id','country_id']].drop_duplicates(keep='first')   
     cities = {}     countries = {}     i=0     for df_temp in 
   chunker(df_unique,24):         print(i)         gtc_service = 
   ads_client.get_service("GeoTargetConstantService", version="v8")         
   location_names = ads_client.get_type("SuggestGeoTargetConstantsRequest", 
   version="v8").GeoTargets()         
   location_names.geo_target_constants.extend(df_temp['city_id'].unique())     
       results = gtc_service.suggest_geo_target_constants(location_names)     
       for suggestion in results.geo_target_constant_suggestions:             
   geo_target_constant = suggestion.geo_target_constant             
   temp_cities = {}             temp_cities[geo_target_constant.resource_name] 
   = geo_target_constant.name             cities.update(temp_cities)           
     for geo_target_constant_parents in 
   suggestion.geo_target_constant_parents:                 if 
   geo_target_constant_parents.target_type == "Country":                     
   temp_countries = {}                     
   temp_countries[geo_target_constant_parents.resource_name] = 
   geo_target_constant_parents.name                     
   countries.update(temp_countries)         i=i+1     df_city = 
   pd.DataFrame(cities.items(),columns=['city_id', 'city'])     df_country = 
   pd.DataFrame(countries.items(),columns=['country_id', 'country'])     df = 
   df_orig.merge(df_city, how='left', on=['city_id']).merge(df_country, 
   how='left', on=['country_id'])     return df*
   
In simple terms, all I am trying to do is map the ids with the names 
present in this CSV: 
https://developers.google.com/google-ads/api/reference/data/geotargets#download_csv_of_geo_targets

It used to work earlier. Can't see any change in these services in the 
migration docs, so kindly help....

Thanks

-- 












This email is intended only for the person or the entity to 
whom it is addressed. If you are not the intended recipient, please delete 
this email and contact the sender.

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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/57477cc0-056f-4e35-b0a2-84532d95478an%40googlegroups.com.
  • Mi... 'Shreyans Jain' via AdWords API and Google Ads API Forum
    • ... Google Ads API Forum Advisor
      • ... 'Shreyans Jain' via AdWords API and Google Ads API Forum
        • ... Google Ads API Forum Advisor
          • ... cv
            • ... 'Google Ads API Forum Advisor' via AdWords API and Google Ads API Forum
              • ... cv
                • ... 'Google Ads API Forum Advisor' via AdWords API and Google Ads API Forum
                • ... Chirag eReportz
                • ... 'Google Ads API Forum Advisor' via AdWords API and Google Ads API Forum
                • ... mqaraev946

Reply via email to