Skip to content

Commit

Permalink
Changes for Google Ads API v2_0. (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
BenRKarl authored Jun 27, 2019
1 parent afbfda7 commit 25b43aa
Show file tree
Hide file tree
Showing 1,468 changed files with 178,845 additions and 236 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
* 3.0.0:
- Google Ads v2_0 release

* 2.4.1:
- Fix bug preventing login_customer_id to be loaded as an int

Expand Down
5 changes: 3 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,17 @@ With the release of Google Ads API v1_0 it's now possible to specify an API
version when getting services and types. The ``get_service`` and ``get_type``
client methods accept a second named parameter, ``version`` that refers to a
valid API version. For example, to request an instance of the
``GoogleAdsService`` that uses Google Ads API version ``v1`` use the
``GoogleAdsService`` that uses Google Ads API version ``v2`` use the
following:

.. code-block:: python
google_ads_service = client.get_service('GoogleAdsService', version='v1')
google_ads_service = client.get_service('GoogleAdsService', version='v2')
The currently available list of versions is:

* ``'v1'``
* ``'v2'``

Enabling and Configuring logging
################################
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 @@ -31,8 +31,8 @@


def main(client, manager_customer_id):
customer_service = client.get_service('CustomerService', version='v1')
customer = client.get_type('Customer', version='v1')
customer_service = client.get_service('CustomerService', version='v2')
customer = client.get_type('Customer', version='v2')
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 @@ -58,7 +58,7 @@ def resource_name_for_resource_type(resource_type, row):


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

resource_type_enum = (client.get_type(
'ChangeStatusResourceTypeEnum', version='v1').ChangeStatusResourceType)
'ChangeStatusResourceTypeEnum', version='v2').ChangeStatusResourceType)
change_status_operation_enum = (client.get_type(
'ChangeStatusOperationEnum', version='v1').ChangeStatusOperation)
'ChangeStatusOperationEnum', version='v2').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 @@ -27,7 +27,7 @@


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

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 @@ -37,14 +37,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='v1')
'CustomerClientLinkOperation', version='v2')
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='v1')
'CustomerClientLinkService', version='v2')
response = customer_client_link_service.mutate_customer_client_link(
manager_customer_id, client_link_operation)
resource_name = response.results[0].resource_name
Expand All @@ -66,7 +66,7 @@ def main(client, customer_id, manager_customer_id):
customer_client_link.resource_name = "{}"
'''.format(resource_name)

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

# Since the google_ads_service.search method returns an iterator we need
Expand All @@ -76,18 +76,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='v1')
'CustomerManagerLinkOperation', version='v2')
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='v1')
manager_link.status = client.get_type('ManagerLinkStatusEnum', version='v2')
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='v1')
version='v2')
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 @@ -28,7 +28,7 @@


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

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 @@ -27,9 +27,9 @@


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

# Create ad group bid modifier for mobile devices with the specified ad
# group ID and bid modifier value.
Expand All @@ -46,7 +46,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='v1').MOBILE
version='v2').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 @@ -66,7 +66,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='v1')
ad_group_service = client.get_service('AdGroupService', version='v2')
ad_group_resource_name = ad_group_service.ad_group_path(customer_id,
ad_group_id)

Expand Down Expand Up @@ -96,14 +96,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='v1')
feed_operation = client.get_type('FeedOperation', version='v2')
# Create a new feed.
feed = feed_operation.create
feed.name.value = 'DSA Feed #{}'.format(uuid.uuid4())
feed.origin = client.get_type('FeedOriginEnum', version='v1').USER
feed.origin = client.get_type('FeedOriginEnum', version='v2').USER

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

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

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

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

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

# Maps specific fields in each row in the response to a dict. This would
Expand All @@ -169,14 +169,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='v1')
version='v2')
# Create a new feed mapping.
feed_mapping = feed_mapping_operation.create
feed_mapping.criterion_type = client.get_type(
'FeedMappingCriterionTypeEnum', version='v1').DSA_PAGE_FEED
'FeedMappingCriterionTypeEnum', version='v2').DSA_PAGE_FEED
feed_mapping.feed.value = feed_details.resource_name
dsa_page_feed_field_enum = client.get_type('DsaPageFeedCriterionFieldEnum',
version='v1')
version='v2')

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

# Retrieve the feed mapping service.
feed_mapping_service = client.get_service('FeedMappingService',
version='v1')
version='v2')
# Submit the feed mapping operation and add the feed mapping.
response = feed_mapping_service.mutate_feed_mappings(
customer_id, [feed_mapping_operation])
Expand All @@ -215,7 +215,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='v1')
feed_item_operation = client.get_type('FeedItemOperation', version='v2')
feed_item = feed_item_operation.create
feed_item.feed.value = feed_details.resource_name

Expand All @@ -237,7 +237,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='v1')
feed_item_service = client.get_service('FeedItemService', version='v2')
# 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 @@ -269,7 +269,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='v1')
ga_service = client.get_service('GoogleAdsService', version='v2')
results = ga_service.search(customer_id, query=query)

for row in results:
Expand All @@ -284,7 +284,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='v1')
campaign_operation = client.get_type('CampaignOperation', version='v2')
# Copy the retrieved campaign onto the new campaign operation.
campaign_operation.update.CopyFrom(campaign)
updated_campaign = campaign_operation.update
Expand All @@ -296,7 +296,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='v1')
campaign_service = client.get_service('CampaignService', version='v2')
# Submit the campaign operation and update the campaign.
response = campaign_service.mutate_campaigns(customer_id,
[campaign_operation])
Expand All @@ -317,7 +317,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='v1')
'AdGroupCriterionOperation', version='v2')
# 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 @@ -328,11 +328,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='v1').CUSTOM_LABEL
'WebpageConditionOperandEnum', version='v2').CUSTOM_LABEL

# Retrieve the ad group criterion service.
ad_group_criterion_service = client.get_service('AdGroupCriterionService',
version='v1')
version='v2')
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 25b43aa

Please sign in to comment.