Skip to content

Commit

Permalink
Changes for release v0_5. (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
David Wihl authored Nov 1, 2018
1 parent 8ef148f commit 14173d9
Show file tree
Hide file tree
Showing 252 changed files with 16,275 additions and 974 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* 0.4.0:
- Google Ads v0_5 release.
- Adding remarketing/add_conversion_action.py example.

* 0.3.0:
- Google Ads v0_4 release.
- Resolving GitHub issue #3:
Expand Down
Empty file added __init__.py
Empty file.
120 changes: 120 additions & 0 deletions examples/v0/account_management/get_account_changes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
#!/usr/bin/env python
#
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""This example gets the changes in the account made in the last 7 days."""

from __future__ import absolute_import

import argparse
import sys

import six

import google.ads.google_ads.client


ADS_PAGE_SIZE = 1000


def resource_name_for_resource_type(resource_type, row):
"""Return the resource name for the resource type.
Each returned row contains all possible changed fields. This function
returns the resource name of the changed field based on the
resource type. The changed field's parent is also populated but is not used.
Args:
resource_type: the string equivalent of the resource type
row: a single row returned from the service
Returns:
The resource name of the field that changed.
"""
resource_name = '' # default for UNSPECIFIED or UNKNOWN
if resource_type == 'AD_GROUP':
resource_name = row.change_status.ad_group.value
elif resource_type == 'AD_GROUP_AD':
resource_name = row.change_status.ad_group_ad.value
elif resource_type == 'AD_GROUP_CRITERION':
resource_name = row.change_status.ad_group_criterion.value
elif resource_type == 'CAMPAIGN':
resource_name = row.change_status.campaign.value
elif resource_type == 'CAMPAIGN_CRITERION':
resource_name = row.change_status.campaign_criterion.value
return resource_name


def main(client, customer_id):
ads_service = client.get_service('GoogleAdsService')
query = ('SELECT change_status.resource_name, '
'change_status.last_change_date_time, '
'change_status.resource_type, '
'change_status.campaign, '
'change_status.ad_group, '
'change_status.resource_status, '
'change_status.ad_group_ad, '
'change_status.ad_group_criterion, '
'change_status.campaign_criterion '
'FROM change_status '
'WHERE change_status.last_change_date_time DURING LAST_7_DAYS '
'ORDER BY change_status.last_change_date_time')

response = ads_service.search(customer_id, query=query,
page_size=ADS_PAGE_SIZE)

resource_type_enum = (client.get_type('ChangeStatusResourceTypeEnum')
.ChangeStatusResourceType)
change_status_operation_enum = (client.get_type('ChangeStatusOperationEnum')
.ChangeStatusOperation)

try:
for row in response:
resource_type = (resource_type_enum.Name(row.change_status
.resource_type))
resource_status = (change_status_operation_enum
.Name(row.change_status.resource_status))
print ('On "%s", change status "%s" shows a resource type of "%s" '
'with resource name "%s" was "%s".'
% (row.change_status.last_change_date_time.value,
row.change_status.resource_name,
resource_type,
resource_name_for_resource_type(resource_type, row),
resource_status))
except google.ads.google_ads.errors.GoogleAdsException as ex:
print('Request with ID "%s" failed with status "%s" and includes the '
'following errors:' % (ex.request_id, ex.error.code().name))
for error in ex.failure.errors:
print('\tError with message "%s".' % error.message)
if error.location:
for field_path_element in error.location.field_path_elements:
print('\t\tOn field: %s' % field_path_element.field_name)
sys.exit(1)


if __name__ == '__main__':
# GoogleAdsClient will read a google-ads.yaml configuration file in the
# home directory if none is specified.
google_ads_client = (google.ads.google_ads.client.GoogleAdsClient
.load_from_storage())

parser = argparse.ArgumentParser(
description=('Displays account changes that occurred in the last 7 days.'))
# The following argument(s) should be provided to run the example.
parser.add_argument('-c', '--customer_id', type=six.text_type,
required=True, help='The Google Ads customer ID.')
args = parser.parse_args()

main(google_ads_client, args.customer_id)
2 changes: 1 addition & 1 deletion examples/v0/account_management/get_account_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def main(client, customer_id):
'customer\'s advertising account.'))
# The following argument(s) should be provided to run the example.
parser.add_argument('-c', '--customer_id', type=six.text_type,
required=True, help='The AdWords customer ID.')
required=True, help='The Google Ads customer ID.')
args = parser.parse_args()

main(google_ads_client, args.customer_id)
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def main(client, customer_id, ad_group_id, bid_modifier_value):
'ID, for the given customer ID.'))
# The following argument(s) should be provided to run the example.
parser.add_argument('-c', '--customer_id', type=six.text_type,
required=True, help='The AdWords customer ID.')
required=True, help='The Google Ads customer ID.')
parser.add_argument('-a', '--ad_group_id', type=six.text_type,
required=True, help='The ad group ID.')
parser.add_argument('-b', '--bid_modifier_value', type=float,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def main(client, customer_id, ad_group_id):
'for the given customer ID.'))
# The following argument(s) should be provided to run the example.
parser.add_argument('-c', '--customer_id', type=six.text_type,
required=True, help='The AdWords customer ID.')
required=True, help='The Google Ads customer ID.')
parser.add_argument('-a', '--ad_group_id', type=six.text_type,
required=True, help='The ad group ID.')
args = parser.parse_args()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def main(client, customer_id, campaign_id):
'provided campaign, for the specified customer.'))
# The following argument(s) should be provided to run the example.
parser.add_argument('-c', '--customer_id', type=six.text_type,
required=True, help='The AdWords customer ID.')
required=True, help='The Google Ads customer ID.')
parser.add_argument('-i', '--campaign_id', type=six.text_type,
required=True, help='The campaign ID.')
args = parser.parse_args()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def main(client, customer_id, page_size, campaign_id):
'criteria under them.'))
# The following argument(s) should be provided to run the example.
parser.add_argument('-c', '--customer_id', type=six.text_type,
required=True, help='The AdWords customer ID.')
required=True, help='The Google Ads customer ID.')
parser.add_argument('-i', '--campaign_id', type=six.text_type,
required=True, help='The campaign ID.')
args = parser.parse_args()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def main(client, customer_id):
description='Adds a campaign for specified customer.')
# The following argument(s) should be provided to run the example.
parser.add_argument('-c', '--customer_id', type=six.text_type,
required=True, help='The AdWords customer ID.')
required=True, help='The Google Ads customer ID.')
args = parser.parse_args()

main(google_ads_client, args.customer_id)
2 changes: 1 addition & 1 deletion examples/v0/basic_operations/add_ad_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def main(client, customer_id, campaign_id):
description='Adds an ad group for specified customer and campaign id.')
# The following argument(s) should be provided to run the example.
parser.add_argument('-c', '--customer_id', type=six.text_type,
required=True, help='The AdWords customer ID.')
required=True, help='The Google Ads customer ID.')
parser.add_argument('-i', '--campaign_id', type=six.text_type,
required=True, help='The campaign ID.')
args = parser.parse_args()
Expand Down
2 changes: 1 addition & 1 deletion examples/v0/basic_operations/add_campaigns.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def main(client, customer_id):
description='Adds a campaign for specified customer.')
# The following argument(s) should be provided to run the example.
parser.add_argument('-c', '--customer_id', type=six.text_type,
required=True, help='The AdWords customer ID.')
required=True, help='The Google Ads customer ID.')
args = parser.parse_args()

main(google_ads_client, args.customer_id)
2 changes: 1 addition & 1 deletion examples/v0/basic_operations/add_expanded_text_ads.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def main(client, customer_id, ad_group_id):
'for the given customer ID.'))
# The following argument(s) should be provided to run the example.
parser.add_argument('-c', '--customer_id', type=six.text_type,
required=True, help='The AdWords customer ID.')
required=True, help='The Google Ads customer ID.')
parser.add_argument('-a', '--ad_group_id', type=six.text_type,
required=True, help='The ad group ID.')
args = parser.parse_args()
Expand Down
2 changes: 1 addition & 1 deletion examples/v0/basic_operations/add_keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def main(client, customer_id, ad_group_id, keyword):
'specified customer.'))
# The following argument(s) should be provided to run the example.
parser.add_argument('-c', '--customer_id', type=six.text_type,
required=True, help='The AdWords customer ID.')
required=True, help='The Google Ads customer ID.')
parser.add_argument('-a', '--ad_group_id', type=six.text_type,
required=True, help='The ad group ID.')
parser.add_argument('-k', '--keyword', type=six.text_type, required=False,
Expand Down
2 changes: 1 addition & 1 deletion examples/v0/basic_operations/get_ad_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def main(client, customer_id, page_size, campaign_id=None):
description='List ad groups for specified customer.')
# The following argument(s) should be provided to run the example.
parser.add_argument('-c', '--customer_id', type=six.text_type,
required=True, help='The AdWords customer ID.')
required=True, help='The Google Ads customer ID.')
parser.add_argument('-i', '--campaign_id', type=six.text_type,
required=False,
help=('The campaign ID. Specify this to list ad groups '
Expand Down
2 changes: 1 addition & 1 deletion examples/v0/basic_operations/get_campaigns.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def main(client, customer_id, page_size):
description='Lists all campaigns for specified customer.')
# The following argument(s) should be provided to run the example.
parser.add_argument('-c', '--customer_id', type=six.text_type,
required=True, help='The AdWords customer ID.')
required=True, help='The Google Ads customer ID.')
args = parser.parse_args()

main(google_ads_client, args.customer_id, _DEFAULT_PAGE_SIZE)
2 changes: 1 addition & 1 deletion examples/v0/basic_operations/get_expanded_text_ads.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def main(client, customer_id, page_size, ad_group_id=None):
description='List ad groups for specified customer.')
# The following argument(s) should be provided to run the example.
parser.add_argument('-c', '--customer_id', type=six.text_type,
required=True, help='The AdWords customer ID.')
required=True, help='The Google Ads customer ID.')
parser.add_argument('-a', '--ad_group_id', type=six.text_type,
required=False, help='The ad group ID. ')
args = parser.parse_args()
Expand Down
2 changes: 1 addition & 1 deletion examples/v0/basic_operations/get_keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def main(client, customer_id, page_size, ad_group_id=None):
'optionally for a specific ad group.'))
# The following argument(s) should be provided to run the example.
parser.add_argument('-c', '--customer_id', type=six.text_type,
required=True, help='The AdWords customer ID.')
required=True, help='The Google Ads customer ID.')
parser.add_argument('-a', '--ad_group_id', type=six.text_type,
required=False, help='The ad group ID.')
args = parser.parse_args()
Expand Down
2 changes: 1 addition & 1 deletion examples/v0/basic_operations/pause_ad.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def main(client, customer_id, ad_group_id, ad_id):
description=('Pauses an ad in the specified customer\'s ad group.'))
# The following argument(s) should be provided to run the example.
parser.add_argument('-c', '--customer_id', type=six.text_type,
required=True, help='The AdWords customer ID.')
required=True, help='The Google Ads customer ID.')
parser.add_argument('-a', '--ad_group_id', type=six.text_type,
required=True, help='The ad group ID.')
parser.add_argument('-i', '--ad_id', type=six.text_type, required=True,
Expand Down
2 changes: 1 addition & 1 deletion examples/v0/basic_operations/remove_ad.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def main(client, customer_id, ad_group_id, ad_id):
description=('Removes an ad from the specified customer\'s ad group.'))
# The following argument(s) should be provided to run the example.
parser.add_argument('-c', '--customer_id', type=six.text_type,
required=True, help='The AdWords customer ID.')
required=True, help='The Google Ads customer ID.')
parser.add_argument('-a', '--ad_group_id', type=six.text_type,
required=True, help='The ad group ID.')
parser.add_argument('-i', '--ad_id', type=six.text_type, required=True,
Expand Down
2 changes: 1 addition & 1 deletion examples/v0/basic_operations/remove_ad_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def main(client, customer_id, ad_group_id):
description=('Removes an ad group for the specified customer.'))
# The following argument(s) should be provided to run the example.
parser.add_argument('-c', '--customer_id', type=six.text_type,
required=True, help='The AdWords customer ID.')
required=True, help='The Google Ads customer ID.')
parser.add_argument('-a', '--ad_group_id', type=six.text_type,
required=True, help='The ad group ID.')
args = parser.parse_args()
Expand Down
2 changes: 1 addition & 1 deletion examples/v0/basic_operations/remove_campaign.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def main(client, customer_id, campaign_id):
description=('Removes given campaign for the specified customer.'))
# The following argument(s) should be provided to run the example.
parser.add_argument('-c', '--customer_id', type=six.text_type,
required=True, help='The AdWords customer ID.')
required=True, help='The Google Ads customer ID.')
parser.add_argument('-i', '--campaign_id', type=six.text_type,
required=True, help='The campaign ID.')
args = parser.parse_args()
Expand Down
2 changes: 1 addition & 1 deletion examples/v0/basic_operations/remove_keyword.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def main(client, customer_id, ad_group_id, criteria_id):
description=('Removes given campaign for the specified customer.'))
# The following argument(s) should be provided to run the example.
parser.add_argument('-c', '--customer_id', type=six.text_type,
required=True, help='The AdWords customer ID.')
required=True, help='The Google Ads customer ID.')
parser.add_argument('-a', '--ad_group_id', type=six.text_type,
required=True, help='The ad group ID.')
parser.add_argument('-k', '--criteria_id', type=six.text_type,
Expand Down
2 changes: 1 addition & 1 deletion examples/v0/basic_operations/update_ad_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def main(client, customer_id, ad_group_id, bid_micro_amount):
'id with the given bid micro amount.'))
# The following argument(s) should be provided to run the example.
parser.add_argument('-c', '--customer_id', type=six.text_type,
required=True, help='The AdWords customer ID.')
required=True, help='The Google Ads customer ID.')
parser.add_argument('-a', '--ad_group_id', type=six.text_type,
required=True, help='The ad group ID.')
parser.add_argument('-b', '--bid_micro_amount', type=int,
Expand Down
2 changes: 1 addition & 1 deletion examples/v0/basic_operations/update_campaign.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def main(client, customer_id, campaign_id):
description='Updates the given campaign for the specified customer.')
# The following argument(s) should be provided to run the example.
parser.add_argument('-c', '--customer_id', type=six.text_type,
required=True, help='The AdWords customer ID.')
required=True, help='The Google Ads customer ID.')
parser.add_argument('-i', '--campaign_id', type=six.text_type,
required=True, help='The campaign ID.')
args = parser.parse_args()
Expand Down
2 changes: 1 addition & 1 deletion examples/v0/basic_operations/update_keyword.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def main(client, customer_id, ad_group_id, criterion_id):
description=('Pauses an ad in the specified customer\'s ad group.'))
# The following argument(s) should be provided to run the example.
parser.add_argument('-c', '--customer_id', type=six.text_type,
required=True, help='The AdWords customer ID.')
required=True, help='The Google Ads customer ID.')
parser.add_argument('-a', '--ad_group_id', type=six.text_type,
required=True, help='The ad group ID.')
parser.add_argument('-k', '--criterion_id', type=six.text_type,
Expand Down
Loading

0 comments on commit 14173d9

Please sign in to comment.