2929
3030from google .ads .googleads .client import GoogleAdsClient
3131from google .ads .googleads .errors import GoogleAdsException
32+ from google .ads .googleads .v19 .services .services .google_ads_service import GoogleAdsServiceClient
33+ from google .ads .googleads .v19 .services .types .google_ads_service import SearchGoogleAdsRequest
34+ from google .ads .googleads .v19 .services .types .google_ads_service import SearchGoogleAdsStreamRequest
35+ from google .ads .googleads .v19 .services .types .google_ads_service import SearchGoogleAdsStreamResponse
3236from google .api_core .exceptions import DeadlineExceeded
3337from google .api_core .retry import Retry
3438
3539
36- _CLIENT_TIMEOUT_SECONDS = 5 * 60 # 5 minutes.
40+ _CLIENT_TIMEOUT_SECONDS : int = 5 * 60 # 5 minutes.
3741_QUERY : str = "SELECT campaign.id FROM campaign"
3842
3943
@@ -53,14 +57,16 @@ def make_server_streaming_call(
5357 client: An initialized GoogleAds client.
5458 customer_id: The str Google Ads customer ID.
5559 """
56- ga_service = client .get_service ("GoogleAdsService" )
57- campaign_ids : List [str ] = []
60+ ga_service : GoogleAdsServiceClient = client .get_service ("GoogleAdsService" )
61+ campaign_ids : list [str ] = []
5862
5963 try :
60- search_request = client .get_type ("SearchGoogleAdsStreamRequest" )
64+ search_request : SearchGoogleAdsStreamRequest = client .get_type (
65+ "SearchGoogleAdsStreamRequest"
66+ )
6167 search_request .customer_id = customer_id
6268 search_request .query = _QUERY
63- stream = ga_service .search_stream (
69+ stream : SearchGoogleAdsStreamResponse = ga_service .search_stream (
6470 request = search_request ,
6571 # When making any request, an optional "timeout" parameter can be
6672 # provided to specify a client-side response deadline in seconds.
@@ -75,7 +81,7 @@ def make_server_streaming_call(
7581 campaign_ids .append (row .campaign .id )
7682
7783 print ("The server streaming call completed before the timeout." )
78- except DeadlineExceeded as ex :
84+ except DeadlineExceeded :
7985 print ("The server streaming call did not complete before the timeout." )
8086 sys .exit (1 )
8187 except GoogleAdsException as ex :
@@ -102,14 +108,16 @@ def make_unary_call(client: GoogleAdsClient, customer_id: str) -> None:
102108 client: An initialized GoogleAds client.
103109 customer_id: The Google Ads customer ID.
104110 """
105- ga_service = client .get_service ("GoogleAdsService" )
106- campaign_ids : List [str ] = []
111+ ga_service : GoogleAdsServiceClient = client .get_service ("GoogleAdsService" )
112+ campaign_ids : list [str ] = []
107113
108114 try :
109- search_request = client .get_type ("SearchGoogleAdsRequest" )
115+ search_request : SearchGoogleAdsRequest = client .get_type (
116+ "SearchGoogleAdsRequest"
117+ )
110118 search_request .customer_id = customer_id
111119 search_request .query = _QUERY
112- results = ga_service .search (
120+ results : SearchGoogleAdsStreamResponse = ga_service .search (
113121 request = search_request ,
114122 # When making any request, an optional "retry" parameter can be
115123 # provided to specify its retry behavior. Complete information about
@@ -137,7 +145,7 @@ def make_unary_call(client: GoogleAdsClient, customer_id: str) -> None:
137145 campaign_ids .append (row .campaign .id )
138146
139147 print ("The unary call completed before the timeout." )
140- except DeadlineExceeded as ex :
148+ except DeadlineExceeded :
141149 print ("The unary call did not complete before the timeout." )
142150 sys .exit (1 )
143151 except GoogleAdsException as ex :
0 commit comments