Skip to content

Commit 7d6c1e7

Browse files
committed
AdWords v201406 release
1 parent d24f8cb commit 7d6c1e7

File tree

98 files changed

+7433
-12
lines changed

Some content is hidden

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

98 files changed

+7433
-12
lines changed

ChangeLog

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
1.0.7 - 07/7/2014
2+
=================
3+
* Added support for v201406 of the AdWords/DoubleClick Ad Exchange Client
4+
Library.
5+
* Added CampaignSharedSetService, LabelService, SharedCriterionService, and
6+
SharedSetService for AdWords.
7+
* Updated AdWords OAuth 2.0 scope.
8+
See: https://developers.google.com/adwords/api/docs/guides/authentication.
9+
110
1.0.6 - 05/29/2014
211
==================
312
* Add support for v201405 for DFP client library.

examples/adwords/authentication/generate_refresh_token.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
HTTPS_PROXY = None
3333

3434
# The AdWords API OAuth 2.0 scope.
35-
SCOPE = u'https://adwords.google.com/api/adwords'
35+
SCOPE = u'https://www.googleapis.com/auth/adwords'
3636
# This callback URL will allow you to copy the token from the success screen.
3737
CALLBACK_URL = 'urn:ietf:wg:oauth:2.0:oob'
3838
# The HTTP headers needed on OAuth 2.0 refresh requests.

examples/adwords/v201402/account_management/create_account.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
1919
Note by default this account will only be accessible via parent MCC.
2020
21-
Note: this code example won't work with test accounts. See
22-
https://developers.google.com/adwords/api/docs/test-accounts
23-
2421
The LoadFromStorage method is pulling credentials and properties from a
2522
"googleads.yaml" file. By default, it looks for this file in your home
2623
directory. For more information, see the "Caching authentication information"

examples/adwords/v201402/basic_operations/get_campaigns_with_awql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
directory. For more information, see the "Caching authentication information"
2424
section of our README.
2525
26-
Tags: CampaignService.get
26+
Tags: CampaignService.query
2727
"""
2828

2929
__author__ = ('[email protected] (Kevin Winter)'

examples/adwords/v201406/__init__.py

Whitespace-only changes.

examples/adwords/v201406/account_management/__init__.py

Whitespace-only changes.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/python
2+
#
3+
# Copyright 2014 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 parent MCC.
20+
21+
The LoadFromStorage method is pulling credentials and properties from a
22+
"googleads.yaml" file. By default, it looks for this file in your home
23+
directory. For more information, see the "Caching authentication information"
24+
section of our README.
25+
26+
Tags: CreateAccountService.mutate
27+
Api: AdWordsOnly
28+
"""
29+
30+
__author__ = ('[email protected] (Kevin Winter)'
31+
'Joseph DiLallo')
32+
33+
from datetime import datetime
34+
35+
from googleads import adwords
36+
37+
38+
def main(client):
39+
# Initialize appropriate service.
40+
managed_customer_service = client.GetService(
41+
'ManagedCustomerService', version='v201406')
42+
43+
today = datetime.today().strftime('%Y%m%d %H:%M:%S')
44+
# Construct operations and add campaign.
45+
operations = [{
46+
'operator': 'ADD',
47+
'operand': {
48+
'name': 'Account created with ManagedCustomerService on %s' % today,
49+
'currencyCode': 'EUR',
50+
'dateTimeZone': 'Europe/London',
51+
}
52+
}]
53+
54+
# Create the account. It is possible to create multiple accounts with one
55+
# request by sending an array of operations.
56+
accounts = managed_customer_service.mutate(operations)
57+
58+
# Display results.
59+
for account in accounts['value']:
60+
print ('Account with customer ID \'%s\' was successfully created.'
61+
% account['customerId'])
62+
63+
64+
if __name__ == '__main__':
65+
# Initialize client object.
66+
adwords_client = adwords.AdWordsClient.LoadFromStorage()
67+
main(adwords_client)
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/usr/bin/python
2+
#
3+
# Copyright 2014 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 all alerts for all clients of an MCC account.
18+
19+
This example assumes the email and password belong to an MCC.
20+
21+
Note: this code example won't work with test accounts. See
22+
https://developers.google.com/adwords/api/docs/test-accounts
23+
24+
The LoadFromStorage method is pulling credentials and properties from a
25+
"googleads.yaml" file. By default, it looks for this file in your home
26+
directory. For more information, see the "Caching authentication information"
27+
section of our README.
28+
29+
Tags: AlertService.get
30+
Api: AdWordsOnly
31+
"""
32+
33+
__author__ = ('[email protected] (Kevin Winter)'
34+
'Joseph DiLallo')
35+
from googleads import adwords
36+
37+
38+
PAGE_SIZE = 500
39+
40+
41+
def main(client):
42+
# Initialize appropriate service.
43+
alert_service = client.GetService('AlertService', version='v201406')
44+
45+
# Construct selector and get all alerts.
46+
offset = 0
47+
selector = {
48+
'query': {
49+
'clientSpec': 'ALL',
50+
'filterSpec': 'ALL',
51+
'types': ['ACCOUNT_BUDGET_BURN_RATE', 'ACCOUNT_BUDGET_ENDING',
52+
'ACCOUNT_ON_TARGET', 'CAMPAIGN_ENDED', 'CAMPAIGN_ENDING',
53+
'CREDIT_CARD_EXPIRING', 'DECLINED_PAYMENT',
54+
'KEYWORD_BELOW_MIN_CPC', 'MANAGER_LINK_PENDING',
55+
'MISSING_BANK_REFERENCE_NUMBER', 'PAYMENT_NOT_ENTERED',
56+
'TV_ACCOUNT_BUDGET_ENDING', 'TV_ACCOUNT_ON_TARGET',
57+
'TV_ZERO_DAILY_SPENDING_LIMIT', 'USER_INVITE_ACCEPTED',
58+
'USER_INVITE_PENDING', 'ZERO_DAILY_SPENDING_LIMIT'],
59+
'severities': ['GREEN', 'YELLOW', 'RED'],
60+
'triggerTimeSpec': 'ALL_TIME'
61+
},
62+
'paging': {
63+
'startIndex': str(offset),
64+
'numberResults': str(PAGE_SIZE)
65+
}
66+
}
67+
more_pages = True
68+
while more_pages:
69+
page = alert_service.get(selector)
70+
# Display results.
71+
if 'entries' in page:
72+
for alert in page['entries']:
73+
print ('Alert of type \'%s\' and severity \'%s\' for account \'%s\' was'
74+
' found.' % (alert['alertType'], alert['alertSeverity'],
75+
alert['clientCustomerId']))
76+
else:
77+
print 'No alerts were found.'
78+
offset += PAGE_SIZE
79+
selector['paging']['startIndex'] = str(offset)
80+
more_pages = offset < int(page['totalNumEntries'])
81+
82+
83+
if __name__ == '__main__':
84+
# Initialize client object.
85+
adwords_client = adwords.AdWordsClient.LoadFromStorage()
86+
main(adwords_client)
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/usr/bin/python
2+
#
3+
# Copyright 2014 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+
Tags: CustomerSyncService.get
25+
"""
26+
27+
__author__ = ('[email protected] (Kevin Winter)'
28+
'Joseph DiLallo')
29+
30+
import datetime
31+
32+
from googleads import adwords
33+
34+
35+
def main(client):
36+
# Initialize appropriate service.
37+
customer_sync_service = client.GetService(
38+
'CustomerSyncService', version='v201406')
39+
campaign_service = client.GetService('CampaignService', version='v201406')
40+
41+
# Construct selector and get all campaigns.
42+
selector = {
43+
'fields': ['Id', 'Name', 'Status']
44+
}
45+
campaigns = campaign_service.get(selector)
46+
campaign_ids = []
47+
if 'entries' in campaigns:
48+
for campaign in campaigns['entries']:
49+
campaign_ids.append(campaign['id'])
50+
else:
51+
print 'No campaigns were found.'
52+
return
53+
54+
# Construct selector and get all changes.
55+
today = datetime.datetime.today()
56+
yesterday = today - datetime.timedelta(1)
57+
selector = {
58+
'dateTimeRange': {
59+
'min': yesterday.strftime('%Y%m%d %H%M%S'),
60+
'max': today.strftime('%Y%m%d %H%M%S')
61+
},
62+
'campaignIds': campaign_ids
63+
}
64+
account_changes = customer_sync_service.get(selector)
65+
66+
# Display results.
67+
if account_changes:
68+
if 'lastChangeTimestamp' in account_changes:
69+
print 'Most recent changes: %s' % account_changes['lastChangeTimestamp']
70+
if account_changes['changedCampaigns']:
71+
for data in account_changes['changedCampaigns']:
72+
print ('Campaign with id \'%s\' has change status \'%s\'.'
73+
% (data['campaignId'], data['campaignChangeStatus']))
74+
if (data['campaignChangeStatus'] != 'NEW' and
75+
data['campaignChangeStatus'] != 'FIELDS_UNCHANGED'):
76+
print ' Added ad extensions: %s' % data.get('addedAdExtensions')
77+
print ' Removed ad extensions: %s' % data.get('deletedAdExtensions')
78+
print (' Added campaign criteria: %s'
79+
% data.get('addedCampaignCriteria'))
80+
print (' Removed campaign criteria: %s'
81+
% data.get('deletedCampaignCriteria'))
82+
print (' Campaign targeting changed: %s'
83+
% data.get('campaignTargetingChanged'))
84+
if data.get('changedAdGroups'):
85+
for ad_group_data in data['changedAdGroups']:
86+
print (' Ad group with id \'%s\' has change status \'%s\'.'
87+
% (ad_group_data['adGroupId'],
88+
ad_group_data['adGroupChangeStatus']))
89+
if ad_group_data['adGroupChangeStatus'] != 'NEW':
90+
print ' Changed ads: %s' % ad_group_data['changedAds']
91+
print (' Changed criteria: %s'
92+
% ad_group_data['changedCriteria'])
93+
print (' Removed criteria: %s'
94+
% ad_group_data['deletedCriteria'])
95+
else:
96+
print 'No changes were found.'
97+
98+
99+
if __name__ == '__main__':
100+
# Initialize client object.
101+
adwords_client = adwords.AdWordsClient.LoadFromStorage()
102+
main(adwords_client)
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/usr/bin/python
2+
#
3+
# Copyright 2014 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+
Note: this code example won't work with test accounts. See
20+
https://developers.google.com/adwords/api/docs/test-accounts
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+
Tags: ServicedAccountService.get
28+
Api: AdWordsOnly
29+
"""
30+
31+
__author__ = ('[email protected] (Kevin Winter)'
32+
'Joseph DiLallo')
33+
34+
from googleads import adwords
35+
36+
37+
def DisplayAccountTree(account, accounts, links, depth=0):
38+
"""Displays an account tree.
39+
40+
Args:
41+
account: dict The account to display.
42+
accounts: dict Map from customerId to account.
43+
links: dict Map from customerId to child links.
44+
depth: int Depth of the current account in the tree.
45+
"""
46+
prefix = '-' * depth * 2
47+
print '%s%s, %s, %s' % (prefix, account['login'], account['customerId'],
48+
account['name'])
49+
if account['customerId'] in links:
50+
for child_link in links[account['customerId']]:
51+
child_account = accounts[child_link['clientCustomerId']]
52+
DisplayAccountTree(child_account, accounts, links, depth + 1)
53+
54+
55+
def main(client):
56+
# Initialize appropriate service.
57+
managed_customer_service = client.GetService(
58+
'ManagedCustomerService', version='v201406')
59+
60+
# Construct selector to get all accounts.
61+
selector = {
62+
'fields': ['Login', 'CustomerId', 'Name']
63+
}
64+
# Get serviced account graph.
65+
graph = managed_customer_service.get(selector)
66+
if 'entries' in graph and graph['entries']:
67+
# Create map from customerId to parent and child links.
68+
child_links = {}
69+
parent_links = {}
70+
if 'links' in graph:
71+
for link in graph['links']:
72+
if link['managerCustomerId'] not in child_links:
73+
child_links[link['managerCustomerId']] = []
74+
child_links[link['managerCustomerId']].append(link)
75+
if link['clientCustomerId'] not in parent_links:
76+
parent_links[link['clientCustomerId']] = []
77+
parent_links[link['clientCustomerId']].append(link)
78+
# Create map from customerID to account and find root account.
79+
accounts = {}
80+
root_account = None
81+
for account in graph['entries']:
82+
accounts[account['customerId']] = account
83+
if account['customerId'] not in parent_links:
84+
root_account = account
85+
# Display account tree.
86+
if root_account:
87+
print 'Login, CustomerId, Name'
88+
DisplayAccountTree(root_account, accounts, child_links, 0)
89+
else:
90+
print 'Unable to determine a root account'
91+
else:
92+
print 'No serviced accounts were found'
93+
94+
95+
if __name__ == '__main__':
96+
# Initialize client object.
97+
adwords_client = adwords.AdWordsClient.LoadFromStorage()
98+
main(adwords_client)

0 commit comments

Comments
 (0)