Skip to content

Commit 14173d9

Browse files
author
David Wihl
authored
Changes for release v0_5. (#12)
1 parent 8ef148f commit 14173d9

File tree

252 files changed

+16275
-974
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

252 files changed

+16275
-974
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* 0.4.0:
2+
- Google Ads v0_5 release.
3+
- Adding remarketing/add_conversion_action.py example.
4+
15
* 0.3.0:
26
- Google Ads v0_4 release.
37
- Resolving GitHub issue #3:

__init__.py

Whitespace-only changes.
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#!/usr/bin/env python
2+
#
3+
# Copyright 2018 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
"""This example gets the changes in the account made in the last 7 days."""
18+
19+
from __future__ import absolute_import
20+
21+
import argparse
22+
import sys
23+
24+
import six
25+
26+
import google.ads.google_ads.client
27+
28+
29+
ADS_PAGE_SIZE = 1000
30+
31+
32+
def resource_name_for_resource_type(resource_type, row):
33+
"""Return the resource name for the resource type.
34+
35+
Each returned row contains all possible changed fields. This function
36+
returns the resource name of the changed field based on the
37+
resource type. The changed field's parent is also populated but is not used.
38+
39+
Args:
40+
resource_type: the string equivalent of the resource type
41+
row: a single row returned from the service
42+
43+
Returns:
44+
The resource name of the field that changed.
45+
"""
46+
resource_name = '' # default for UNSPECIFIED or UNKNOWN
47+
if resource_type == 'AD_GROUP':
48+
resource_name = row.change_status.ad_group.value
49+
elif resource_type == 'AD_GROUP_AD':
50+
resource_name = row.change_status.ad_group_ad.value
51+
elif resource_type == 'AD_GROUP_CRITERION':
52+
resource_name = row.change_status.ad_group_criterion.value
53+
elif resource_type == 'CAMPAIGN':
54+
resource_name = row.change_status.campaign.value
55+
elif resource_type == 'CAMPAIGN_CRITERION':
56+
resource_name = row.change_status.campaign_criterion.value
57+
return resource_name
58+
59+
60+
def main(client, customer_id):
61+
ads_service = client.get_service('GoogleAdsService')
62+
query = ('SELECT change_status.resource_name, '
63+
'change_status.last_change_date_time, '
64+
'change_status.resource_type, '
65+
'change_status.campaign, '
66+
'change_status.ad_group, '
67+
'change_status.resource_status, '
68+
'change_status.ad_group_ad, '
69+
'change_status.ad_group_criterion, '
70+
'change_status.campaign_criterion '
71+
'FROM change_status '
72+
'WHERE change_status.last_change_date_time DURING LAST_7_DAYS '
73+
'ORDER BY change_status.last_change_date_time')
74+
75+
response = ads_service.search(customer_id, query=query,
76+
page_size=ADS_PAGE_SIZE)
77+
78+
resource_type_enum = (client.get_type('ChangeStatusResourceTypeEnum')
79+
.ChangeStatusResourceType)
80+
change_status_operation_enum = (client.get_type('ChangeStatusOperationEnum')
81+
.ChangeStatusOperation)
82+
83+
try:
84+
for row in response:
85+
resource_type = (resource_type_enum.Name(row.change_status
86+
.resource_type))
87+
resource_status = (change_status_operation_enum
88+
.Name(row.change_status.resource_status))
89+
print ('On "%s", change status "%s" shows a resource type of "%s" '
90+
'with resource name "%s" was "%s".'
91+
% (row.change_status.last_change_date_time.value,
92+
row.change_status.resource_name,
93+
resource_type,
94+
resource_name_for_resource_type(resource_type, row),
95+
resource_status))
96+
except google.ads.google_ads.errors.GoogleAdsException as ex:
97+
print('Request with ID "%s" failed with status "%s" and includes the '
98+
'following errors:' % (ex.request_id, ex.error.code().name))
99+
for error in ex.failure.errors:
100+
print('\tError with message "%s".' % error.message)
101+
if error.location:
102+
for field_path_element in error.location.field_path_elements:
103+
print('\t\tOn field: %s' % field_path_element.field_name)
104+
sys.exit(1)
105+
106+
107+
if __name__ == '__main__':
108+
# GoogleAdsClient will read a google-ads.yaml configuration file in the
109+
# home directory if none is specified.
110+
google_ads_client = (google.ads.google_ads.client.GoogleAdsClient
111+
.load_from_storage())
112+
113+
parser = argparse.ArgumentParser(
114+
description=('Displays account changes that occurred in the last 7 days.'))
115+
# The following argument(s) should be provided to run the example.
116+
parser.add_argument('-c', '--customer_id', type=six.text_type,
117+
required=True, help='The Google Ads customer ID.')
118+
args = parser.parse_args()
119+
120+
main(google_ads_client, args.customer_id)

examples/v0/account_management/get_account_information.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def main(client, customer_id):
6161
'customer\'s advertising account.'))
6262
# The following argument(s) should be provided to run the example.
6363
parser.add_argument('-c', '--customer_id', type=six.text_type,
64-
required=True, help='The AdWords customer ID.')
64+
required=True, help='The Google Ads customer ID.')
6565
args = parser.parse_args()
6666

6767
main(google_ads_client, args.customer_id)

examples/v0/advanced_operations/add_ad_group_bid_modifiers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def main(client, customer_id, ad_group_id, bid_modifier_value):
7575
'ID, for the given customer ID.'))
7676
# The following argument(s) should be provided to run the example.
7777
parser.add_argument('-c', '--customer_id', type=six.text_type,
78-
required=True, help='The AdWords customer ID.')
78+
required=True, help='The Google Ads customer ID.')
7979
parser.add_argument('-a', '--ad_group_id', type=six.text_type,
8080
required=True, help='The ad group ID.')
8181
parser.add_argument('-b', '--bid_modifier_value', type=float,

examples/v0/advanced_operations/add_expanded_text_ad_with_upgraded_urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def main(client, customer_id, ad_group_id):
101101
'for the given customer ID.'))
102102
# The following argument(s) should be provided to run the example.
103103
parser.add_argument('-c', '--customer_id', type=six.text_type,
104-
required=True, help='The AdWords customer ID.')
104+
required=True, help='The Google Ads customer ID.')
105105
parser.add_argument('-a', '--ad_group_id', type=six.text_type,
106106
required=True, help='The ad group ID.')
107107
args = parser.parse_args()

examples/v0/advanced_operations/create_and_attach_shared_keyword_sets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def main(client, customer_id, campaign_id):
117117
'provided campaign, for the specified customer.'))
118118
# The following argument(s) should be provided to run the example.
119119
parser.add_argument('-c', '--customer_id', type=six.text_type,
120-
required=True, help='The AdWords customer ID.')
120+
required=True, help='The Google Ads customer ID.')
121121
parser.add_argument('-i', '--campaign_id', type=six.text_type,
122122
required=True, help='The campaign ID.')
123123
args = parser.parse_args()

examples/v0/advanced_operations/find_and_remove_criteria_from_shared_set.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def main(client, customer_id, page_size, campaign_id):
128128
'criteria under them.'))
129129
# The following argument(s) should be provided to run the example.
130130
parser.add_argument('-c', '--customer_id', type=six.text_type,
131-
required=True, help='The AdWords customer ID.')
131+
required=True, help='The Google Ads customer ID.')
132132
parser.add_argument('-i', '--campaign_id', type=six.text_type,
133133
required=True, help='The campaign ID.')
134134
args = parser.parse_args()

examples/v0/advanced_operations/use_portfolio_bidding_strategy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def main(client, customer_id):
133133
description='Adds a campaign for specified customer.')
134134
# The following argument(s) should be provided to run the example.
135135
parser.add_argument('-c', '--customer_id', type=six.text_type,
136-
required=True, help='The AdWords customer ID.')
136+
required=True, help='The Google Ads customer ID.')
137137
args = parser.parse_args()
138138

139139
main(google_ads_client, args.customer_id)

examples/v0/basic_operations/add_ad_groups.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def main(client, customer_id, campaign_id):
6767
description='Adds an ad group for specified customer and campaign id.')
6868
# The following argument(s) should be provided to run the example.
6969
parser.add_argument('-c', '--customer_id', type=six.text_type,
70-
required=True, help='The AdWords customer ID.')
70+
required=True, help='The Google Ads customer ID.')
7171
parser.add_argument('-i', '--campaign_id', type=six.text_type,
7272
required=True, help='The campaign ID.')
7373
args = parser.parse_args()

0 commit comments

Comments
 (0)