2424import argparse
2525import sys
2626import uuid
27- from typing import Any
2827
2928from google .ads .googleads .client import GoogleAdsClient
3029from google .ads .googleads .errors import GoogleAdsException
30+ from google .ads .googleads .v20 .resources .types .ad_group import AdGroup
31+ from google .ads .googleads .v20 .resources .types .ad_group_ad import AdGroupAd
32+ from google .ads .googleads .v20 .resources .types .campaign import Campaign
33+ from google .ads .googleads .v20 .resources .types .campaign_budget import (
34+ CampaignBudget ,
35+ )
36+ from google .ads .googleads .v20 .services .services .ad_group_ad_service import (
37+ AdGroupAdServiceClient ,
38+ )
39+ from google .ads .googleads .v20 .services .services .ad_group_service import (
40+ AdGroupServiceClient ,
41+ )
42+ from google .ads .googleads .v20 .services .services .campaign_budget_service import (
43+ CampaignBudgetServiceClient ,
44+ )
45+ from google .ads .googleads .v20 .services .services .campaign_service import (
46+ CampaignServiceClient ,
47+ )
48+ from google .ads .googleads .v20 .services .types .ad_group_ad_service import (
49+ AdGroupAdOperation ,
50+ MutateAdGroupAdsResponse ,
51+ )
52+ from google .ads .googleads .v20 .services .types .ad_group_service import (
53+ AdGroupOperation ,
54+ MutateAdGroupsResponse ,
55+ )
56+ from google .ads .googleads .v20 .services .types .campaign_budget_service import (
57+ CampaignBudgetOperation ,
58+ MutateCampaignBudgetsResponse ,
59+ )
60+ from google .ads .googleads .v20 .services .types .campaign_service import (
61+ CampaignOperation ,
62+ MutateCampaignsResponse ,
63+ )
3164
3265
3366def main (
@@ -54,19 +87,23 @@ def main(
5487
5588
5689def add_budget (client : GoogleAdsClient , customer_id : str ) -> str :
57- campaign_budget_service : Any = client .get_service ("CampaignBudgetService" )
90+ campaign_budget_service : CampaignBudgetServiceClient = client .get_service (
91+ "CampaignBudgetService"
92+ )
5893
5994 # Create a budget, which can be shared by multiple campaigns.
60- campaign_budget_operation : Any = client .get_type ("CampaignBudgetOperation" )
61- campaign_budget : Any = campaign_budget_operation .create
95+ campaign_budget_operation : CampaignBudgetOperation = client .get_type (
96+ "CampaignBudgetOperation"
97+ )
98+ campaign_budget : CampaignBudget = campaign_budget_operation .create
6299 campaign_budget .name = f"Interplanetary Budget { uuid .uuid4 ()} "
63100 campaign_budget .delivery_method = (
64101 client .enums .BudgetDeliveryMethodEnum .STANDARD
65102 )
66103 campaign_budget .amount_micros = 500000
67104
68105 # Add budget.
69- campaign_budget_response : Any = (
106+ campaign_budget_response : MutateCampaignBudgetsResponse = (
70107 campaign_budget_service .mutate_campaign_budgets (
71108 customer_id = customer_id , operations = [campaign_budget_operation ]
72109 )
@@ -85,11 +122,13 @@ def add_budget(client: GoogleAdsClient, customer_id: str) -> str:
85122def add_hotel_ad (
86123 client : GoogleAdsClient , customer_id : str , ad_group_resource_name : str
87124) -> str :
88- ad_group_ad_service : Any = client .get_service ("AdGroupAdService" )
125+ ad_group_ad_service : AdGroupAdServiceClient = client .get_service (
126+ "AdGroupAdService"
127+ )
89128
90129 # Creates a new ad group ad and sets the hotel ad to it.
91- ad_group_ad_operation : Any = client .get_type ("AdGroupAdOperation" )
92- ad_group_ad : Any = ad_group_ad_operation .create
130+ ad_group_ad_operation : AdGroupAdOperation = client .get_type ("AdGroupAdOperation" )
131+ ad_group_ad : AdGroupAd = ad_group_ad_operation .create
93132 ad_group_ad .ad_group = ad_group_resource_name
94133 # Set the ad group ad to enabled. Setting this to paused will cause an error
95134 # for hotel campaigns. For hotels pausing should happen at either the ad group or
@@ -98,7 +137,7 @@ def add_hotel_ad(
98137 client .copy_from (ad_group_ad .ad .hotel_ad , client .get_type ("HotelAdInfo" ))
99138
100139 # Add the ad group ad.
101- ad_group_ad_response : Any = ad_group_ad_service .mutate_ad_group_ads (
140+ ad_group_ad_response : MutateAdGroupAdsResponse = ad_group_ad_service .mutate_ad_group_ads (
102141 customer_id = customer_id , operations = [ad_group_ad_operation ]
103142 )
104143
@@ -116,11 +155,11 @@ def add_hotel_ad(
116155def add_hotel_ad_group (
117156 client : GoogleAdsClient , customer_id : str , campaign_resource_name : str
118157) -> str :
119- ad_group_service : Any = client .get_service ("AdGroupService" )
158+ ad_group_service : AdGroupServiceClient = client .get_service ("AdGroupService" )
120159
121160 # Create ad group.
122- ad_group_operation : Any = client .get_type ("AdGroupOperation" )
123- ad_group : Any = ad_group_operation .create
161+ ad_group_operation : AdGroupOperation = client .get_type ("AdGroupOperation" )
162+ ad_group : AdGroup = ad_group_operation .create
124163 ad_group .name = f"Earth to Mars cruise { uuid .uuid4 ()} "
125164 ad_group .status = client .enums .AdGroupStatusEnum .ENABLED
126165 ad_group .campaign = campaign_resource_name
@@ -129,7 +168,7 @@ def add_hotel_ad_group(
129168 ad_group .cpc_bid_micros = 10000000
130169
131170 # Add the ad group.
132- ad_group_response : Any = ad_group_service .mutate_ad_groups (
171+ ad_group_response : MutateAdGroupsResponse = ad_group_service .mutate_ad_groups (
133172 customer_id = customer_id , operations = [ad_group_operation ]
134173 )
135174
@@ -151,12 +190,12 @@ def add_hotel_campaign(
151190 hotel_center_account_id : int ,
152191 cpc_bid_ceiling_micro_amount : int ,
153192) -> str :
154- campaign_service : Any = client .get_service ("CampaignService" )
193+ campaign_service : CampaignServiceClient = client .get_service ("CampaignService" )
155194
156195 # [START add_hotel_ad_1]
157196 # Create campaign.
158- campaign_operation : Any = client .get_type ("CampaignOperation" )
159- campaign : Any = campaign_operation .create
197+ campaign_operation : CampaignOperation = client .get_type ("CampaignOperation" )
198+ campaign : Campaign = campaign_operation .create
160199 campaign .name = f"Interplanetary Cruise Campaign { uuid .uuid4 ()} "
161200
162201 # Configures settings related to hotel campaigns including advertising
@@ -184,7 +223,7 @@ def add_hotel_campaign(
184223 # [END add_hotel_ad_1]
185224
186225 # Add the campaign.
187- campaign_response : Any = campaign_service .mutate_campaigns (
226+ campaign_response : MutateCampaignsResponse = campaign_service .mutate_campaigns (
188227 customer_id = customer_id , operations = [campaign_operation ]
189228 )
190229
0 commit comments