Hi,
For past few days I have a similar issue like this
one: https://groups.google.com/g/adwords-api/c/Gx4QN7ER33s?pli=1. I need to
get the campaign data from 2014. I am querying the API search stream in a
loop with start & end date difference of 2 days, this loop will continue
until I get all the data from 2014. After few loop iterations
the SearchGoogleAdsStreamRequest is stuck, without any error/warning logs.
I have standard level API access. Please let me know what should i have to
do.
This is my code:
import my_sql_queries
def _get_pmax_reports_for_client(self, ga_client: object, customer_id: int,
start_date: str, end_date: str, retries: int = 0) -> customerType:
try:
campaign_data_request =
ga_client.get_type("SearchGoogleAdsStreamRequest")
campaign_data_request.customer_id = str(customer_id)
type_campaign_status_enum = ga_client.get_type('CampaignStatusEnum')
type_advertising_channel_enum =
ga_client.get_type('AdvertisingChannelTypeEnum')
type_advertising_channel_sub_enum =
ga_client.get_type('AdvertisingChannelSubTypeEnum')
type_bidding_strategy_enum =
ga_client.get_type('BiddingStrategyTypeEnum')
campaign_data_request.query =
my_sql_queries.get_pmax_reports_for_client_query.format(start_date=start_date,
end_date=end_date)
ga_service = ga_client.get_service("GoogleAdsService",
version='v13')
campaign_data_stream =
ga_service.search_stream(campaign_data_request)
pmax_campaign_data_list = []
for batch in campaign_data_stream:
for row in batch.results:
row_list = {
'ROW_ID': row.segments.date + '_' +
str(row.campaign.id),
'REPORT_DATE_LOC': row.segments.date,
'CAMPAIGN_ID': row.campaign.id,
'CAMPAIGN_NAME': row.campaign.name,
'BASE_CAMPAIGN_ID': re.sub('.*campaigns/', '',
row.campaign.base_campaign),
'CAMPAIGN_STATUS':
str(type_campaign_status_enum.CampaignStatus.Name(
row.campaign.status)).lower(),
'CAMPAIGN_TYPE':
str(type_advertising_channel_enum.AdvertisingChannelType.Name(
row.campaign.advertising_channel_type)).lower(),
'CAMPAIGN_SUB_TYPE':
str(type_advertising_channel_sub_enum.AdvertisingChannelSubType.Name(
row.campaign.advertising_channel_sub_type)).lower(),
'BIDDING_STRATEGY_TYPE':
str(type_bidding_strategy_enum.BiddingStrategyType.Name(
row.campaign.bidding_strategy_type)).lower(),
'CTR': row.metrics.ctr,
'VIEW_THROUGH_CONVERSIONS':
row.metrics.view_through_conversions,
'CROSS_DEVICE_CONVERSIONS':
row.metrics.cross_device_conversions,
'ENGAGEMENTS': row.metrics.engagements,
'VIDEO_VIEWS': row.metrics.video_views,
'ALL_CONVERSIONS': row.metrics.all_conversions,
'COST': row.metrics.cost_micros,
'COST_PER_CONVERSION': row.metrics.cost_per_conversion,
'CONVERSION_VALUE': row.metrics.conversions_value,
'PERCENT_NEW_VISITORS':
row.metrics.percent_new_visitors,
'VIDEO_VIEW_RATE': row.metrics.video_view_rate,
'AVERAGE_TIME_ON_SITE':
row.metrics.average_time_on_site,
'IMPRESSIONS': row.metrics.impressions,
'ENGAGEMENT_RATE': row.metrics.engagement_rate,
'EXTERNAL_CUSTOMER_ID': row.customer.id,
'BOUNCE_RATE': row.metrics.bounce_rate,
'AVERAGE_PAGEVIEWS': row.metrics.average_page_views,
'ACCOUNT_DESCRIPTIVE_NAME':
row.customer.descriptive_name,
'CONVERSION_RATE':
row.metrics.conversions_from_interactions_rate,
'CONVERSIONS': row.metrics.conversions,
'INTERACTION_RATE': row.metrics.interaction_rate,
'INTERACTIONS': row.metrics.interactions,
'CLICKS': row.metrics.clicks,
'ACCOUNT_TIMEZONE_STANDARD': row.customer.time_zone,
'ACCOUNT_CURRENCY_CODE': row.customer.currency_code,
'CUSTOMER_ID': customer_id
}
pmax_campaign_data_list.append(row_list)
return pmax_campaign_data_list
except Exception as e:
error_text = str(e)
if ('429' in error_text or '500' in error_text or '503' in
error_text) and retries <= 60:
logging.error(f'Retrying after encountering Server Error.
{error_text}')
sleep(60)
return self._get_pmax_reports_for_client(ga_client,
customer_id, start_date, end_date,
retries=retries + 1)
else:
logging.error(f'Error occurred while getting data from Google
Ads API (v13). {error_text}')
raise
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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
"Google Ads API and AdWords 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/f18b85b0-887a-4ff0-bd31-55b80831a9c1n%40googlegroups.com.