Skip to content

Commit 0b0452e

Browse files
committed
AdWords v201506 release
1 parent b3a12c6 commit 0b0452e

File tree

108 files changed

+8974
-84
lines changed

Some content is hidden

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

108 files changed

+8974
-84
lines changed

ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
3.5.0 - 6/26/2015
2+
* Added support for v201506 of the AdWords Client Library.
3+
* Reporting parameters in ReportDownloader utility now in **kwargs.
4+
* Added new "include_zero_impressions" reporting parameter as keyword argument
5+
for ReportDownloader utility methods.
6+
17
3.4.1 - 5/22/2015
28
* Fixed issue #55
39
* Fixed issue #57

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,4 @@ suds_client.service.mutate([operation])
127127

128128

129129
##Authors:
130-
jdilallo@google.com (Joseph DiLallo)
130+
msaniscalchi@google.com (Mark Saniscalchi)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2015 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 2015 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: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/python
2+
#
3+
# Copyright 2015 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='v201506')
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: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/usr/bin/python
2+
#
3+
# Copyright 2015 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='v201506')
39+
campaign_service = client.GetService('CampaignService', version='v201506')
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+
if data.get('changedAdGroups'):
83+
for ad_group_data in data['changedAdGroups']:
84+
print (' Ad group with id \'%s\' has change status \'%s\'.'
85+
% (ad_group_data['adGroupId'],
86+
ad_group_data['adGroupChangeStatus']))
87+
if ad_group_data['adGroupChangeStatus'] != 'NEW':
88+
print ' Changed ads: %s' % ad_group_data['changedAds']
89+
print (' Changed criteria: %s'
90+
% ad_group_data['changedCriteria'])
91+
print (' Removed criteria: %s'
92+
% ad_group_data['deletedCriteria'])
93+
else:
94+
print 'No changes were found.'
95+
96+
97+
if __name__ == '__main__':
98+
# Initialize client object.
99+
adwords_client = adwords.AdWordsClient.LoadFromStorage()
100+
main(adwords_client)
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/usr/bin/python
2+
#
3+
# Copyright 2015 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' % (prefix, account['customerId'], account['name'])
48+
if account['customerId'] in links:
49+
for child_link in links[account['customerId']]:
50+
child_account = accounts[child_link['clientCustomerId']]
51+
DisplayAccountTree(child_account, accounts, links, depth + 1)
52+
53+
54+
def main(client):
55+
# Initialize appropriate service.
56+
managed_customer_service = client.GetService(
57+
'ManagedCustomerService', version='v201506')
58+
59+
# Construct selector to get all accounts.
60+
selector = {
61+
'fields': ['CustomerId', 'Name']
62+
}
63+
# Get serviced account graph.
64+
graph = managed_customer_service.get(selector)
65+
if 'entries' in graph and graph['entries']:
66+
# Create map from customerId to parent and child links.
67+
child_links = {}
68+
parent_links = {}
69+
if 'links' in graph:
70+
for link in graph['links']:
71+
if link['managerCustomerId'] not in child_links:
72+
child_links[link['managerCustomerId']] = []
73+
child_links[link['managerCustomerId']].append(link)
74+
if link['clientCustomerId'] not in parent_links:
75+
parent_links[link['clientCustomerId']] = []
76+
parent_links[link['clientCustomerId']].append(link)
77+
# Create map from customerID to account and find root account.
78+
accounts = {}
79+
root_account = None
80+
for account in graph['entries']:
81+
accounts[account['customerId']] = account
82+
if account['customerId'] not in parent_links:
83+
root_account = account
84+
# Display account tree.
85+
if root_account:
86+
print 'CustomerId, Name'
87+
DisplayAccountTree(root_account, accounts, child_links, 0)
88+
else:
89+
print 'Unable to determine a root account'
90+
else:
91+
print 'No serviced accounts were found'
92+
93+
94+
if __name__ == '__main__':
95+
# Initialize client object.
96+
adwords_client = adwords.AdWordsClient.LoadFromStorage()
97+
main(adwords_client)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2015 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)