Device, status value is returning as enum instead name
Hi, I am using v11 latest google ads api library while I am trying to fetch campaign.status & segments.device value it gives me enum as value instead of name
so please suggest me way to resolve it
below is my python code
def get_campaigns(client, customer_id, from_date, to_date):
cols_with_periods=['segments.date',
'customer.id',
'campaign.id',
'campaign.name',
'segments.device',
'metrics.impressions',
'metrics.clicks',
'metrics.cost_micros'
]
cols_without_periods=[c.replace('.', '_') for c in cols_with_periods[0:-2]]
data = []
query = """
SELECT {},{},{},{},{},{},{},{}
FROM campaign
where segments.date >= '2022-09-01' AND segments.date <= '2022-09-22'
ORDER BY segments.date DESC, campaign.id ASC, metrics.impressions DESC
""".format(*cols_with_periods)
print('Query: ', query)
ga_service = client.get_service("GoogleAdsService")
search_request = client.get_type("SearchGoogleAdsStreamRequest")
search_request.customer_id = customer_id
search_request.query = query
stream = ga_service.search_stream(search_request)
try:
for batch in stream:
for row in batch.results:
cols_prefix_rows=['row.'+c for c in cols_with_periods[0:-2]]
new_data=[str(row.segments.date),
str(row.customer.id),
str(row.campaign.id),
str(row.campaign.name),
str(row.segments.device),
str(row.metrics.impressions),
str(row.metrics.clicks),
str(row.metrics.cost_micros)]
data.append(new_data)
except GoogleAdsException as ex:
print(
f'Request with ID "{ex.request_id}" failed with status '
f'"{ex.error.code().name}" and includes the following errors:'
)
for error in ex.failure.errors:
print(f'\tError with message "{error.message}".')
if error.location:
for field_path_element in error.location.field_path_elements:
print(f"\t\tOn field: {field_path_element.field_name}")
sys.exit(1)
#df=spark.createDataFrame(data, cols_without_periods)
return data
I tried to use "row.segments.device.name" but it gives error 'int' object has no attribute 'name' Also use_proto_plus: "True" is set in yaml file.
@neerajnagarro when I run the below test, I consistently get UNSPECIFIED when use_proto_plus is set to true, and the error AttributeError: 'int' object has no attribute 'name' when use_proto_plus is set to false. For the sake of experimentation I tried using true. True, and "True" in my yaml file, and all worked the same:
from google.ads.googleads.client import GoogleAdsClient
client = GoogleAdsClient.load_from_storage()
row = client.get_type("GoogleAdsRow")
print(row.segments.device.name)
Can you confirm that you're using the configuration file that you expect? And that you're not overwriting that configuration with a call to GoogleAdsClient.load_from_dict or GoogleAdsClient.load_from_env?
@neeraj-sharma-nykaa assuming you've overcome this issue and closing this for now, please add more details if not and I'll be happy to help.