2828
2929from google .ads .googleads .client import GoogleAdsClient
3030from 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
3135from google .api_core .exceptions import DeadlineExceeded
3236from google .api_core .retry import Retry
3337
3438
35- _CLIENT_TIMEOUT_SECONDS = 5 * 60 # 5 minutes.
36- _QUERY = "SELECT campaign.id FROM campaign"
39+ _CLIENT_TIMEOUT_SECONDS : int = 5 * 60 # 5 minutes.
40+ _QUERY : str = "SELECT campaign.id FROM campaign"
3741
3842
39- def main (client , customer_id ) :
43+ def main (client : GoogleAdsClient , customer_id : str ) -> None :
4044 """Main method, to run this code example as a standalone application."""
4145 make_server_streaming_call (client , customer_id )
4246 make_unary_call (client , customer_id )
4347
4448
4549# [START set_custom_client_timeouts]
46- def make_server_streaming_call (client , customer_id ):
50+ def make_server_streaming_call (
51+ client : GoogleAdsClient , customer_id : str
52+ ) -> None :
4753 """Makes a server streaming call using a custom client timeout.
4854
4955 Args:
5056 client: An initialized GoogleAds client.
5157 customer_id: The str Google Ads customer ID.
5258 """
53- ga_service = client .get_service ("GoogleAdsService" )
54- campaign_ids = []
59+ ga_service : GoogleAdsServiceClient = client .get_service ("GoogleAdsService" )
60+ campaign_ids : list [ str ] = []
5561
5662 try :
57- search_request = client .get_type ("SearchGoogleAdsStreamRequest" )
63+ search_request : SearchGoogleAdsStreamRequest = client .get_type (
64+ "SearchGoogleAdsStreamRequest"
65+ )
5866 search_request .customer_id = customer_id
5967 search_request .query = _QUERY
60- stream = ga_service .search_stream (
68+ stream : SearchGoogleAdsStreamResponse = ga_service .search_stream (
6169 request = search_request ,
6270 # When making any request, an optional "timeout" parameter can be
6371 # provided to specify a client-side response deadline in seconds.
@@ -72,7 +80,7 @@ def make_server_streaming_call(client, customer_id):
7280 campaign_ids .append (row .campaign .id )
7381
7482 print ("The server streaming call completed before the timeout." )
75- except DeadlineExceeded as ex :
83+ except DeadlineExceeded :
7684 print ("The server streaming call did not complete before the timeout." )
7785 sys .exit (1 )
7886 except GoogleAdsException as ex :
@@ -92,21 +100,23 @@ def make_server_streaming_call(client, customer_id):
92100
93101
94102# [START set_custom_client_timeouts_1]
95- def make_unary_call (client , customer_id ) :
103+ def make_unary_call (client : GoogleAdsClient , customer_id : str ) -> None :
96104 """Makes a unary call using a custom client timeout.
97105
98106 Args:
99107 client: An initialized GoogleAds client.
100108 customer_id: The Google Ads customer ID.
101109 """
102- ga_service = client .get_service ("GoogleAdsService" )
103- campaign_ids = []
110+ ga_service : GoogleAdsServiceClient = client .get_service ("GoogleAdsService" )
111+ campaign_ids : list [ str ] = []
104112
105113 try :
106- search_request = client .get_type ("SearchGoogleAdsRequest" )
114+ search_request : SearchGoogleAdsRequest = client .get_type (
115+ "SearchGoogleAdsRequest"
116+ )
107117 search_request .customer_id = customer_id
108118 search_request .query = _QUERY
109- results = ga_service .search (
119+ results : SearchGoogleAdsStreamResponse = ga_service .search (
110120 request = search_request ,
111121 # When making any request, an optional "retry" parameter can be
112122 # provided to specify its retry behavior. Complete information about
@@ -134,7 +144,7 @@ def make_unary_call(client, customer_id):
134144 campaign_ids .append (row .campaign .id )
135145
136146 print ("The unary call completed before the timeout." )
137- except DeadlineExceeded as ex :
147+ except DeadlineExceeded :
138148 print ("The unary call did not complete before the timeout." )
139149 sys .exit (1 )
140150 except GoogleAdsException as ex :
0 commit comments