Skip to content

Commit b9bb0e9

Browse files
committed
AdWords v201802 release
1 parent 3cc75af commit b9bb0e9

114 files changed

Lines changed: 11756 additions & 63 deletions

File tree

Some content is hidden

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

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
10.1.0 -- 03/01/18
2+
* Added support and examples for AdWords v201802.
3+
* Added new BuildOpener utility method to ProxyConfig, which returns an
4+
OpenerDirector instance configured for the ProxyConfig settings.
5+
16
10.0.0 -- 02/13/18
27
* Added support and examples for DFP v201802.
38
* Removed support and examples for AdWords v201702.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2016 Google Inc. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Examples for AdWords."""
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2016 Google Inc. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Account management examples."""
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env python
2+
#
3+
# Copyright 2016 Google Inc. All Rights Reserved.
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 accepts a pending Google Merchant Center invitation link.
18+
19+
The LoadFromStorage method is pulling credentials and properties from a
20+
"googleads.yaml" file. By default, it looks for this file in your home
21+
directory. For more information, see the "Caching authentication information"
22+
section of our README.
23+
24+
"""
25+
26+
27+
from googleads import adwords
28+
29+
30+
SERVICE_LINK_ID = 'INSERT_SERVICE_LINK_ID_HERE'
31+
32+
33+
def main(client, service_link_id):
34+
# Initialize appropriate service.
35+
customer_service = client.GetService(
36+
'CustomerService', version='v201802')
37+
38+
# Create the operation to set the status to ACTIVE.
39+
operations = [{
40+
'operator': 'SET',
41+
'operand': {
42+
'serviceLinkId': service_link_id,
43+
'serviceType': 'MERCHANT_CENTER',
44+
'linkStatus': 'ACTIVE',
45+
}
46+
}]
47+
48+
# Update the service link.
49+
mutated_service_links = customer_service.mutateServiceLinks(operations)
50+
51+
# Display results.
52+
for mutated_service_link in mutated_service_links:
53+
print ('Service link with service link ID "%s", type "%s" was updated '
54+
'to status: "%s".' % (mutated_service_link['serviceLinkId'],
55+
mutated_service_link['serviceType'],
56+
mutated_service_link['linkStatus']))
57+
58+
59+
if __name__ == '__main__':
60+
# Initialize client object.
61+
adwords_client = adwords.AdWordsClient.LoadFromStorage()
62+
main(adwords_client, SERVICE_LINK_ID)
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/env python
2+
#
3+
# Copyright 2016 Google Inc. All Rights Reserved.
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 illustrates how to create an account.
18+
19+
Note by default this account will only be accessible via its parent AdWords
20+
manager account..
21+
22+
The LoadFromStorage method is pulling credentials and properties from a
23+
"googleads.yaml" file. By default, it looks for this file in your home
24+
directory. For more information, see the "Caching authentication information"
25+
section of our README.
26+
27+
"""
28+
29+
30+
from datetime import datetime
31+
from googleads import adwords
32+
33+
34+
def main(client):
35+
# Initialize appropriate service.
36+
managed_customer_service = client.GetService(
37+
'ManagedCustomerService', version='v201802')
38+
39+
today = datetime.today().strftime('%Y%m%d %H:%M:%S')
40+
# Construct operations and add campaign.
41+
operations = [{
42+
'operator': 'ADD',
43+
'operand': {
44+
'name': 'Account created with ManagedCustomerService on %s' % today,
45+
'currencyCode': 'EUR',
46+
'dateTimeZone': 'Europe/London',
47+
},
48+
# For whitelisted users only, uncomment the inviteeEmail and inviteeRole
49+
# attributes to invite a user to have access to an account on an ADD. An
50+
# email will be sent inviting the user to have access to the newly created
51+
# account.
52+
# 'inviteeEmail': 'invited_user1@example.com',
53+
# 'inviteeRole': 'ADMINISTRATIVE'
54+
}]
55+
56+
# Create the account. It is possible to create multiple accounts with one
57+
# request by sending an array of operations.
58+
accounts = managed_customer_service.mutate(operations)
59+
60+
# Display results.
61+
for account in accounts['value']:
62+
print ('Account with customer ID "%s" was successfully created.'
63+
% account['customerId'])
64+
65+
66+
if __name__ == '__main__':
67+
# Initialize client object.
68+
adwords_client = adwords.AdWordsClient.LoadFromStorage()
69+
main(adwords_client)
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/usr/bin/env python
2+
#
3+
# Copyright 2016 Google Inc. All Rights Reserved.
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 during the last 24 hours.
18+
19+
The LoadFromStorage method is pulling credentials and properties from a
20+
"googleads.yaml" file. By default, it looks for this file in your home
21+
directory. For more information, see the "Caching authentication information"
22+
section of our README.
23+
24+
"""
25+
26+
27+
import datetime
28+
from googleads import adwords
29+
30+
31+
def main(client):
32+
# Initialize appropriate service.
33+
customer_sync_service = client.GetService(
34+
'CustomerSyncService', version='v201802')
35+
campaign_service = client.GetService('CampaignService', version='v201802')
36+
37+
# Construct selector and get all campaigns.
38+
selector = {
39+
'fields': ['Id', 'Name', 'Status']
40+
}
41+
campaigns = campaign_service.get(selector)
42+
campaign_ids = []
43+
if 'entries' in campaigns:
44+
for campaign in campaigns['entries']:
45+
campaign_ids.append(campaign['id'])
46+
else:
47+
print 'No campaigns were found.'
48+
return
49+
50+
# Construct selector and get all changes.
51+
today = datetime.datetime.today()
52+
yesterday = today - datetime.timedelta(1)
53+
selector = {
54+
'dateTimeRange': {
55+
'min': yesterday.strftime('%Y%m%d %H%M%S'),
56+
'max': today.strftime('%Y%m%d %H%M%S')
57+
},
58+
'campaignIds': campaign_ids
59+
}
60+
account_changes = customer_sync_service.get(selector)
61+
62+
# Display results.
63+
if account_changes:
64+
if 'lastChangeTimestamp' in account_changes:
65+
print 'Most recent changes: %s' % account_changes['lastChangeTimestamp']
66+
if account_changes['changedCampaigns']:
67+
for data in account_changes['changedCampaigns']:
68+
print ('Campaign with id "%s" has change status "%s".'
69+
% (data['campaignId'], data['campaignChangeStatus']))
70+
if (data['campaignChangeStatus'] != 'NEW' and
71+
data['campaignChangeStatus'] != 'FIELDS_UNCHANGED'):
72+
if 'addedCampaignCriteria' in data:
73+
print (' Added campaign criteria: %s' %
74+
data['addedCampaignCriteria'])
75+
if 'removedCampaignCriteria' in data:
76+
print (' Removed campaign criteria: %s' %
77+
data['removedCampaignCriteria'])
78+
if 'changedAdGroups' in data:
79+
for ad_group_data in data['changedAdGroups']:
80+
print (' Ad group with id "%s" has change status "%s".'
81+
% (ad_group_data['adGroupId'],
82+
ad_group_data['adGroupChangeStatus']))
83+
if ad_group_data['adGroupChangeStatus'] != 'NEW':
84+
if 'changedAds' in ad_group_data:
85+
print ' Changed ads: %s' % ad_group_data['changedAds']
86+
if 'changedCriteria' in ad_group_data:
87+
print (' Changed criteria: %s' %
88+
ad_group_data['changedCriteria'])
89+
if 'removedCriteria' in ad_group_data:
90+
print (' Removed criteria: %s' %
91+
ad_group_data['removedCriteria'])
92+
else:
93+
print 'No changes were found.'
94+
95+
96+
if __name__ == '__main__':
97+
# Initialize client object.
98+
adwords_client = adwords.AdWordsClient.LoadFromStorage()
99+
main(adwords_client)
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#!/usr/bin/env python
2+
#
3+
# Copyright 2016 Google Inc. All Rights Reserved.
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 account hierarchy under the current account.
18+
19+
The LoadFromStorage method is pulling credentials and properties from a
20+
"googleads.yaml" file. By default, it looks for this file in your home
21+
directory. For more information, see the "Caching authentication information"
22+
section of our README.
23+
24+
"""
25+
from googleads import adwords
26+
27+
28+
PAGE_SIZE = 500
29+
30+
31+
def DisplayAccountTree(account, accounts, links, depth=0):
32+
"""Displays an account tree.
33+
34+
Args:
35+
account: dict The account to display.
36+
accounts: dict Map from customerId to account.
37+
links: dict Map from customerId to child links.
38+
depth: int Depth of the current account in the tree.
39+
"""
40+
prefix = '-' * depth * 2
41+
print '%s%s, %s' % (prefix, account['customerId'], account['name'])
42+
if account['customerId'] in links:
43+
for child_link in links[account['customerId']]:
44+
child_account = accounts[child_link['clientCustomerId']]
45+
DisplayAccountTree(child_account, accounts, links, depth + 1)
46+
47+
48+
def main(client):
49+
# Initialize appropriate service.
50+
managed_customer_service = client.GetService(
51+
'ManagedCustomerService', version='v201802')
52+
53+
# Construct selector to get all accounts.
54+
offset = 0
55+
selector = {
56+
'fields': ['CustomerId', 'Name'],
57+
'paging': {
58+
'startIndex': str(offset),
59+
'numberResults': str(PAGE_SIZE)
60+
}
61+
}
62+
more_pages = True
63+
accounts = {}
64+
child_links = {}
65+
parent_links = {}
66+
root_account = None
67+
68+
while more_pages:
69+
# Get serviced account graph.
70+
page = managed_customer_service.get(selector)
71+
if 'entries' in page and page['entries']:
72+
# Create map from customerId to parent and child links.
73+
if 'links' in page:
74+
for link in page['links']:
75+
if link['managerCustomerId'] not in child_links:
76+
child_links[link['managerCustomerId']] = []
77+
child_links[link['managerCustomerId']].append(link)
78+
if link['clientCustomerId'] not in parent_links:
79+
parent_links[link['clientCustomerId']] = []
80+
parent_links[link['clientCustomerId']].append(link)
81+
# Map from customerID to account.
82+
for account in page['entries']:
83+
accounts[account['customerId']] = account
84+
offset += PAGE_SIZE
85+
selector['paging']['startIndex'] = str(offset)
86+
more_pages = offset < int(page['totalNumEntries'])
87+
88+
# Find the root account.
89+
for customer_id in accounts:
90+
if customer_id not in parent_links:
91+
root_account = accounts[customer_id]
92+
93+
# Display account tree.
94+
if root_account:
95+
print 'CustomerId, Name'
96+
DisplayAccountTree(root_account, accounts, child_links, 0)
97+
else:
98+
print 'Unable to determine a root account'
99+
100+
101+
if __name__ == '__main__':
102+
# Initialize client object.
103+
adwords_client = adwords.AdWordsClient.LoadFromStorage()
104+
main(adwords_client)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2016 Google Inc. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Advanced operations examples."""

0 commit comments

Comments
 (0)