2525
2626import argparse
2727import sys
28+ from typing import List
2829
2930from google .ads .googleads .client import GoogleAdsClient
3031from google .ads .googleads .errors import GoogleAdsException
31- from google .ads .googleads .v19 .services .services .google_ads_service import GoogleAdsServiceClient
32- from google .ads .googleads .v19 .services .types .google_ads_service import SearchGoogleAdsRequest
33- from google .ads .googleads .v19 .services .types .google_ads_service import SearchGoogleAdsStreamRequest
34- from google .ads .googleads .v19 .services .types .google_ads_service import SearchGoogleAdsStreamResponse
3532from google .api_core .exceptions import DeadlineExceeded
3633from google .api_core .retry import Retry
3734
3835
39- _CLIENT_TIMEOUT_SECONDS : int = 5 * 60 # 5 minutes.
36+ _CLIENT_TIMEOUT_SECONDS = 5 * 60 # 5 minutes.
4037_QUERY : str = "SELECT campaign.id FROM campaign"
4138
4239
@@ -56,16 +53,14 @@ def make_server_streaming_call(
5653 client: An initialized GoogleAds client.
5754 customer_id: The str Google Ads customer ID.
5855 """
59- ga_service : GoogleAdsServiceClient = client .get_service ("GoogleAdsService" )
60- campaign_ids : list [str ] = []
56+ ga_service = client .get_service ("GoogleAdsService" )
57+ campaign_ids : List [str ] = []
6158
6259 try :
63- search_request : SearchGoogleAdsStreamRequest = client .get_type (
64- "SearchGoogleAdsStreamRequest"
65- )
60+ search_request = client .get_type ("SearchGoogleAdsStreamRequest" )
6661 search_request .customer_id = customer_id
6762 search_request .query = _QUERY
68- stream : SearchGoogleAdsStreamResponse = ga_service .search_stream (
63+ stream = ga_service .search_stream (
6964 request = search_request ,
7065 # When making any request, an optional "timeout" parameter can be
7166 # provided to specify a client-side response deadline in seconds.
@@ -80,7 +75,7 @@ def make_server_streaming_call(
8075 campaign_ids .append (row .campaign .id )
8176
8277 print ("The server streaming call completed before the timeout." )
83- except DeadlineExceeded :
78+ except DeadlineExceeded as ex :
8479 print ("The server streaming call did not complete before the timeout." )
8580 sys .exit (1 )
8681 except GoogleAdsException as ex :
@@ -107,16 +102,14 @@ def make_unary_call(client: GoogleAdsClient, customer_id: str) -> None:
107102 client: An initialized GoogleAds client.
108103 customer_id: The Google Ads customer ID.
109104 """
110- ga_service : GoogleAdsServiceClient = client .get_service ("GoogleAdsService" )
111- campaign_ids : list [str ] = []
105+ ga_service = client .get_service ("GoogleAdsService" )
106+ campaign_ids : List [str ] = []
112107
113108 try :
114- search_request : SearchGoogleAdsRequest = client .get_type (
115- "SearchGoogleAdsRequest"
116- )
109+ search_request = client .get_type ("SearchGoogleAdsRequest" )
117110 search_request .customer_id = customer_id
118111 search_request .query = _QUERY
119- results : SearchGoogleAdsStreamResponse = ga_service .search (
112+ results = ga_service .search (
120113 request = search_request ,
121114 # When making any request, an optional "retry" parameter can be
122115 # provided to specify its retry behavior. Complete information about
@@ -144,7 +137,7 @@ def make_unary_call(client: GoogleAdsClient, customer_id: str) -> None:
144137 campaign_ids .append (row .campaign .id )
145138
146139 print ("The unary call completed before the timeout." )
147- except DeadlineExceeded :
140+ except DeadlineExceeded as ex :
148141 print ("The unary call did not complete before the timeout." )
149142 sys .exit (1 )
150143 except GoogleAdsException as ex :
0 commit comments