Skip to content

Commit

Permalink
Changes for Google Ads API v3_0. (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
BenRKarl authored Mar 6, 2020
1 parent 0fc8a7d commit 2a72658
Show file tree
Hide file tree
Showing 1,539 changed files with 187,315 additions and 904 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
* 5.0.0
- Google Ads v3_0 release

* 4.1.1:
- Fix for types.py to include classes of dependent modules

Expand Down
4 changes: 2 additions & 2 deletions examples/account_management/create_customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@


def main(client, manager_customer_id):
customer_service = client.get_service('CustomerService', version='v2')
customer = client.get_type('Customer', version='v2')
customer_service = client.get_service('CustomerService', version='v3')
customer = client.get_type('Customer', version='v3')
today = datetime.today().strftime('%Y%m%d %H:%M:%S')
customer.descriptive_name.value = ('Account created with '
'CustomerService on %s' % today)
Expand Down
6 changes: 3 additions & 3 deletions examples/account_management/get_account_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def resource_name_for_resource_type(resource_type, row):


def main(client, customer_id):
ads_service = client.get_service('GoogleAdsService', version='v2')
ads_service = client.get_service('GoogleAdsService', version='v3')
query = ('SELECT change_status.resource_name, '
'change_status.last_change_date_time, '
'change_status.resource_type, '
Expand All @@ -74,9 +74,9 @@ def main(client, customer_id):
page_size=ADS_PAGE_SIZE)

resource_type_enum = (client.get_type(
'ChangeStatusResourceTypeEnum', version='v2').ChangeStatusResourceType)
'ChangeStatusResourceTypeEnum', version='v3').ChangeStatusResourceType)
change_status_operation_enum = (client.get_type(
'ChangeStatusOperationEnum', version='v2').ChangeStatusOperation)
'ChangeStatusOperationEnum', version='v3').ChangeStatusOperation)

try:
for row in response:
Expand Down
2 changes: 1 addition & 1 deletion examples/account_management/get_account_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


def main(client, customer_id):
customer_service = client.get_service('CustomerService', version='v2')
customer_service = client.get_service('CustomerService', version='v3')

resource_name = customer_service.customer_path(customer_id)

Expand Down
12 changes: 6 additions & 6 deletions examples/account_management/link_manager_to_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ def main(client, customer_id, manager_customer_id):

# Extend an invitation to the client while authenticating as the manager.
client_link_operation = client.get_type(
'CustomerClientLinkOperation', version='v2')
'CustomerClientLinkOperation', version='v3')
client_link = client_link_operation.create
client_link.client_customer.value = 'customers/{}'.format(customer_id)
client_link.status = client.get_type(
'ManagerLinkStatusEnum').PENDING

customer_client_link_service = client.get_service(
'CustomerClientLinkService', version='v2')
'CustomerClientLinkService', version='v3')
response = customer_client_link_service.mutate_customer_client_link(
manager_customer_id, client_link_operation)
resource_name = response.results[0].resource_name
Expand All @@ -64,7 +64,7 @@ def main(client, customer_id, manager_customer_id):
customer_client_link.resource_name = "{}"
'''.format(resource_name)

ga_service = client.get_service('GoogleAdsService', version='v2')
ga_service = client.get_service('GoogleAdsService', version='v3')
response = ga_service.search(manager_customer_id, query=query)

# Since the google_ads_service.search method returns an iterator we need
Expand All @@ -74,18 +74,18 @@ def main(client, customer_id, manager_customer_id):
manager_link_id = row.customer_client_link.manager_link_id

manager_link_operation = client.get_type(
'CustomerManagerLinkOperation', version='v2')
'CustomerManagerLinkOperation', version='v3')
manager_link = manager_link_operation.update
manager_link.resource_name.value = (
'customers/{}/customerManagerLinks/{}~{}'.format(
customer_id, manager_customer_id, manager_link_id))

manager_link.status = client.get_type('ManagerLinkStatusEnum', version='v2')
manager_link.status = client.get_type('ManagerLinkStatusEnum', version='v3')
field_mask = protobuf_helpers.field_mask(None, manager_link)
manager_link_operation.update_mask.CopyFrom(field_mask)

manager_link_service = client.get_service('ManagerLinkService',
version='v2')
version='v3')
response = manager_link_service.mutate_manager_links(
manager_customer_id, [manager_link_operation])
resource_name = response.results[0].resource_name
Expand Down
2 changes: 1 addition & 1 deletion examples/account_management/list_accessible_customers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@


def main(client):
customer_service = client.get_service('CustomerService', version='v2')
customer_service = client.get_service('CustomerService', version='v3')

try:
accessible_customers = customer_service.list_accessible_customers()
Expand Down
6 changes: 3 additions & 3 deletions examples/advanced_operations/add_ad_group_bid_modifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@


def main(client, customer_id, ad_group_id, bid_modifier_value):
ad_group_service = client.get_service('AdGroupService', version='v2')
ad_group_service = client.get_service('AdGroupService', version='v3')
ad_group_bm_service = client.get_service('AdGroupBidModifierService',
version='v2')
version='v3')

# Create ad group bid modifier for mobile devices with the specified ad
# group ID and bid modifier value.
Expand All @@ -44,7 +44,7 @@ def main(client, customer_id, ad_group_id, bid_modifier_value):

# Sets the device.
ad_group_bid_modifier.device.type = client.get_type('DeviceEnum',
version='v2').MOBILE
version='v3').MOBILE

# Add the ad group bid modifier.
try:
Expand Down
36 changes: 18 additions & 18 deletions examples/advanced_operations/add_dynamic_page_feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def main(client, customer_id, campaign_id, ad_group_id):
# Associate the page feed with the campaign.
update_campaign_dsa_setting(client, customer_id, campaign_id,
feed_details)
ad_group_service = client.get_service('AdGroupService', version='v2')
ad_group_service = client.get_service('AdGroupService', version='v3')
ad_group_resource_name = ad_group_service.ad_group_path(customer_id,
ad_group_id)

Expand Down Expand Up @@ -94,14 +94,14 @@ def create_feed(client, customer_id):
A FeedDetails instance with information about the newly created feed.
"""
# Retrieve a new feed operation object.
feed_operation = client.get_type('FeedOperation', version='v2')
feed_operation = client.get_type('FeedOperation', version='v3')
# Create a new feed.
feed = feed_operation.create
feed.name.value = 'DSA Feed #{}'.format(uuid.uuid4())
feed.origin = client.get_type('FeedOriginEnum', version='v2').USER
feed.origin = client.get_type('FeedOriginEnum', version='v3').USER

feed_attribute_type_enum = client.get_type('FeedAttributeTypeEnum',
version='v2')
version='v3')

# Create the feed's attributes.
feed_attribute_url = feed.attributes.add()
Expand All @@ -113,7 +113,7 @@ def create_feed(client, customer_id):
feed_attribute_label.name.value = 'Label'

# Retrieve the feed service.
feed_service = client.get_service('FeedService', version='v2')
feed_service = client.get_service('FeedService', version='v3')
# Send the feed operation and add the feed.
response = feed_service.mutate_feeds(customer_id, [feed_operation])

Expand Down Expand Up @@ -142,7 +142,7 @@ def get_feed_details(client, customer_id, resource_name):
LIMIT 1
'''.format(resource_name)

ga_service = client.get_service('GoogleAdsService', version='v2')
ga_service = client.get_service('GoogleAdsService', version='v3')
response = ga_service.search(customer_id, query=query)

# Maps specific fields in each row in the response to a dict. This would
Expand All @@ -167,14 +167,14 @@ def create_feed_mapping(client, customer_id, feed_details):
"""
# Retrieve a new feed mapping operation object.
feed_mapping_operation = client.get_type('FeedMappingOperation',
version='v2')
version='v3')
# Create a new feed mapping.
feed_mapping = feed_mapping_operation.create
feed_mapping.criterion_type = client.get_type(
'FeedMappingCriterionTypeEnum', version='v2').DSA_PAGE_FEED
'FeedMappingCriterionTypeEnum', version='v3').DSA_PAGE_FEED
feed_mapping.feed.value = feed_details.resource_name
dsa_page_feed_field_enum = client.get_type('DsaPageFeedCriterionFieldEnum',
version='v2')
version='v3')

url_field_mapping = feed_mapping.attribute_field_mappings.add()
url_field_mapping.feed_attribute_id.value = feed_details.url_attribute_id
Expand All @@ -187,7 +187,7 @@ def create_feed_mapping(client, customer_id, feed_details):

# Retrieve the feed mapping service.
feed_mapping_service = client.get_service('FeedMappingService',
version='v2')
version='v3')
# Submit the feed mapping operation and add the feed mapping.
response = feed_mapping_service.mutate_feed_mappings(
customer_id, [feed_mapping_operation])
Expand All @@ -213,7 +213,7 @@ def create_feed_items(client, customer_id, feed_details, label):
"http://www.example.com/discounts/flight-deals"]

def map_feed_urls(url):
feed_item_operation = client.get_type('FeedItemOperation', version='v2')
feed_item_operation = client.get_type('FeedItemOperation', version='v3')
feed_item = feed_item_operation.create
feed_item.feed.value = feed_details.resource_name

Expand All @@ -235,7 +235,7 @@ def map_feed_urls(url):
feed_item_operations = list(map(map_feed_urls, urls))

# Retrieve the feed item service.
feed_item_service = client.get_service('FeedItemService', version='v2')
feed_item_service = client.get_service('FeedItemService', version='v3')
# Submit the feed item operations and add the feed items.
response = feed_item_service.mutate_feed_items(customer_id,
feed_item_operations)
Expand Down Expand Up @@ -267,7 +267,7 @@ def update_campaign_dsa_setting(client, customer_id, campaign_id, feed_details):
LIMIT 1
'''.format(campaign_id)

ga_service = client.get_service('GoogleAdsService', version='v2')
ga_service = client.get_service('GoogleAdsService', version='v3')
results = ga_service.search(customer_id, query=query)

for row in results:
Expand All @@ -282,7 +282,7 @@ def update_campaign_dsa_setting(client, customer_id, campaign_id, feed_details):
campaign_id))

# Retrieve a new campaign operation
campaign_operation = client.get_type('CampaignOperation', version='v2')
campaign_operation = client.get_type('CampaignOperation', version='v3')
# Copy the retrieved campaign onto the new campaign operation.
campaign_operation.update.CopyFrom(campaign)
updated_campaign = campaign_operation.update
Expand All @@ -294,7 +294,7 @@ def update_campaign_dsa_setting(client, customer_id, campaign_id, feed_details):
campaign_operation.update_mask.CopyFrom(field_mask)

# Retrieve the campaign service.
campaign_service = client.get_service('CampaignService', version='v2')
campaign_service = client.get_service('CampaignService', version='v3')
# Submit the campaign operation and update the campaign.
response = campaign_service.mutate_campaigns(customer_id,
[campaign_operation])
Expand All @@ -315,7 +315,7 @@ def add_dsa_targeting(client, customer_id, ad_group_resource_name, label):
"""
# Retrieve a new ad group criterion operation object.
ad_group_criterion_operation = client.get_type(
'AdGroupCriterionOperation', version='v2')
'AdGroupCriterionOperation', version='v3')
# Create a new ad group criterion.
ad_group_criterion = ad_group_criterion_operation.create
ad_group_criterion.ad_group.value = ad_group_resource_name
Expand All @@ -326,11 +326,11 @@ def add_dsa_targeting(client, customer_id, ad_group_resource_name, label):
webpage_criterion_info = ad_group_criterion.webpage.conditions.add()
webpage_criterion_info.argument.value = label
webpage_criterion_info.operand = client.get_type(
'WebpageConditionOperandEnum', version='v2').CUSTOM_LABEL
'WebpageConditionOperandEnum', version='v3').CUSTOM_LABEL

# Retrieve the ad group criterion service.
ad_group_criterion_service = client.get_service('AdGroupCriterionService',
version='v2')
version='v3')
response = ad_group_criterion_service.mutate_ad_group_criteria(
customer_id, [ad_group_criterion_operation])
resource_name = response.results[0].resource_name
Expand Down
Loading

0 comments on commit 2a72658

Please sign in to comment.