Skip to content

Commit a63f39b

Browse files
author
Nicholas Chen
committed
update googleads python library to support v201408
1 parent bcb64a7 commit a63f39b

File tree

161 files changed

+9920
-19
lines changed

Some content is hidden

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

161 files changed

+9920
-19
lines changed

ChangeLog

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2.0.1 - 08/20/2014
2+
=================
3+
* Added support for v201408 for DFP client library.
4+
* Removed RateCardCustomizationService and RateCardCustomizationGroupService,
5+
replaced with PremiumRateService.
6+
* Changed OAuth2 scope to https://www.googleapis.com/auth/dfp/
7+
* Changed DFP endpoint to https://ads.google.com/
8+
19
2.0.0 - 07/22/2014
210
=================
311
* AdGroups/Campaigns no longer renamed on remove/delete in examples, obsolete.

examples/dfp/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 DFP API OAuth 2.0 scope.
35-
SCOPE = u'https://www.google.com/apis/ads/publisher'
35+
SCOPE = u'https://www.googleapis.com/auth/dfp'
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/dfp/v201403/custom_targeting_service/get_custom_targeting_keys_by_statement.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def main(client):
3838
'value': 'PREDEFINED'
3939
}
4040
}]
41-
query = 'WHERE type = :type',
41+
query = 'WHERE type = :type'
4242
statement = dfp.FilterStatement(query, values)
4343

4444
# Get custom targeting keys by statement.

examples/dfp/v201405/custom_targeting_service/get_custom_targeting_keys_by_statement.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def main(client):
3838
'value': 'PREDEFINED'
3939
}
4040
}]
41-
query = 'WHERE type = :type',
41+
query = 'WHERE type = :type'
4242
statement = dfp.FilterStatement(query, values)
4343

4444
# Get custom targeting keys by statement.

examples/dfp/v201405/report_service/run_inventory_report.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,13 @@ def main(client):
3939

4040
# Set filter statement and bind value for reportQuery.
4141
values = [{
42-
'key': 'ancestor_ad_unit_id',
42+
'key': 'parent_ad_unit_id',
4343
'value': {
4444
'xsi_type': 'NumberValue',
4545
'value': root_ad_unit_id
4646
}
4747
}]
48-
filter_statement = {'query': 'WHERE AD_UNIT_ANCESTOR_AD_UNIT_ID'
49-
' = :ancestor_ad_unit_id',
48+
filter_statement = {'query': 'WHERE PARENT_AD_UNIT_ID = :parent_ad_unit_id',
5049
'values': values}
5150

5251
# Create report job.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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 code example creates new activity groups.
18+
19+
To determine which activity groups exist, run get_all_activity_groups.py.
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: ActivityGroupService.createActivityGroups
27+
"""
28+
29+
__author__ = ('Vincent Tsao',
30+
'Joseph DiLallo')
31+
32+
import uuid
33+
34+
# Import appropriate modules from the client library.
35+
from googleads import dfp
36+
37+
# Set the ID of the advertiser company this activity group is associated with.
38+
ADVERTISER_COMPANY_ID = 'INSERT_ADVERTISER_COMPANY_ID_HERE'
39+
40+
41+
def main(client, advertiser_company_id):
42+
# Initialize appropriate service.
43+
activity_group_service = client.GetService('ActivityGroupService',
44+
version='v201408')
45+
46+
# Create a short-term activity group.
47+
short_term_activity_group = {
48+
'name': 'Short-term activity group #%s' % uuid.uuid4(),
49+
'companyIds': [advertiser_company_id],
50+
'clicksLookback': '1',
51+
'impressionsLookback': '1'
52+
}
53+
54+
# Create a long-term activity group.
55+
long_term_activity_group = {
56+
'name': 'Long-term activity group #%s' % uuid.uuid4(),
57+
'companyIds': [advertiser_company_id],
58+
'clicksLookback': '30',
59+
'impressionsLookback': '30'
60+
}
61+
62+
# Create the activity groups on the server.
63+
activity_groups = activity_group_service.createActivityGroups([
64+
short_term_activity_group, long_term_activity_group])
65+
66+
# Display results.
67+
for activity_group in activity_groups:
68+
print ('Activity group with ID \'%s\' and name \'%s\' was created.'
69+
% (activity_group['id'], activity_group['name']))
70+
71+
if __name__ == '__main__':
72+
# Initialize client object.
73+
dfp_client = dfp.DfpClient.LoadFromStorage()
74+
main(dfp_client, ADVERTISER_COMPANY_ID)
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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 code example gets all active activity groups.
18+
19+
To create activity groups, run create_activity_groups.py.
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: ActivityGroupService.getActivityGroupsByStatement
27+
"""
28+
29+
__author__ = ('Nicholas Chen',
30+
'Joseph DiLallo')
31+
32+
# Import appropriate modules from the client library.
33+
from googleads import dfp
34+
35+
36+
def main(client):
37+
# Initialize appropriate service.
38+
activity_group_service = client.GetService('ActivityGroupService',
39+
version='v201408')
40+
41+
# Create statement object to only select active activity groups.
42+
values = [{
43+
'key': 'status',
44+
'value': {
45+
'xsi_type': 'TextValue',
46+
'value': 'ACTIVE'
47+
}
48+
}]
49+
query = 'WHERE status = :status'
50+
51+
# Create a filter statement.
52+
statement = dfp.FilterStatement(query, values)
53+
54+
# Get activity groups by statement.
55+
while True:
56+
response = activity_group_service.getActivityGroupsByStatement(
57+
statement.ToStatement())
58+
if 'results' in response:
59+
# Display results.
60+
for activity_group in response['results']:
61+
print ('Activity group with ID \'%s\' and name \'%s\' was found.'
62+
% (activity_group['id'], activity_group['name']))
63+
statement.offset += dfp.SUGGESTED_PAGE_LIMIT
64+
else:
65+
break
66+
67+
print '\nNumber of results found: %s' % response['totalResultSetSize']
68+
69+
if __name__ == '__main__':
70+
# Initialize client object.
71+
dfp_client = dfp.DfpClient.LoadFromStorage()
72+
main(dfp_client)
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 code example gets all activity groups.
18+
19+
To create activity groups, run create_activity_groups.py.
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: ActivityGroupService.getActivityGroupsByStatement
27+
"""
28+
29+
__author__ = ('Nicholas Chen',
30+
'Joseph DiLallo')
31+
32+
# Import appropriate modules from the client library.
33+
from googleads import dfp
34+
35+
36+
def main(client):
37+
# Initialize appropriate service.
38+
activity_group_service = client.GetService('ActivityGroupService',
39+
version='v201408')
40+
41+
# Create a filter statement.
42+
statement = dfp.FilterStatement()
43+
44+
# Get activity groups by statement.
45+
while True:
46+
response = activity_group_service.getActivityGroupsByStatement(
47+
statement.ToStatement())
48+
if 'results' in response:
49+
# Display results.
50+
for activity_group in response['results']:
51+
print ('Activity group with ID \'%s\' and name \'%s\' was found.'
52+
% (activity_group['id'], activity_group['name']))
53+
statement.offset += dfp.SUGGESTED_PAGE_LIMIT
54+
else:
55+
break
56+
57+
print '\nNumber of results found: %s' % response['totalResultSetSize']
58+
59+
60+
if __name__ == '__main__':
61+
# Initialize client object.
62+
dfp_client = dfp.DfpClient.LoadFromStorage()
63+
main(dfp_client)
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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 code example updates activity groups.
18+
19+
To determine which activity groups exist, run get_all_activity_groups.py.
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: ActivityGroupService.getActivityGroup
27+
Tags: ActivityGroupService.updateActivityGroups
28+
"""
29+
30+
__author__ = ('Nicholas Chen',
31+
'Joseph DiLallo')
32+
33+
# Import appropriate modules from the client library.
34+
from googleads import dfp
35+
36+
# Set the ID of the activity group and the company to update it with.
37+
ACTIVITY_GROUP_ID = 'INSERT_ACTIVITY_GROUP_ID_HERE'
38+
ADVERTISER_COMPANY_ID = 'INSERT_ADVERTISER_COMPANY_ID_HERE'
39+
40+
41+
def main(client, activity_group_id, advertiser_company_id):
42+
# Initialize appropriate service.
43+
activity_group_service = client.GetService('ActivityGroupService',
44+
version='v201408')
45+
46+
# Create statement object to select a single activity groups by ID.
47+
values = [{
48+
'key': 'activityGroupId',
49+
'value': {
50+
'xsi_type': 'NumberValue',
51+
'value': activity_group_id
52+
}
53+
}]
54+
query = 'WHERE id = :activityGroupId'
55+
56+
# Create a filter statement.
57+
statement = dfp.FilterStatement(query, values, 1)
58+
59+
# Get activity groups by statement.
60+
response = activity_group_service.getActivityGroupsByStatement(
61+
statement.ToStatement())
62+
if 'results' in response:
63+
updated_activity_groups = []
64+
for activity_group in response['results']:
65+
activity_group['companyIds'].append(advertiser_company_id)
66+
updated_activity_groups.append(activity_group)
67+
# Update the activity groups on the server.
68+
activity_groups = activity_group_service.updateActivityGroups(
69+
updated_activity_groups)
70+
71+
for activity_group in activity_groups:
72+
print (('Activity group with ID \'%s\' and name \'%s\' was updated.')
73+
% (activity_group['id'], activity_group['name']))
74+
else:
75+
print 'No activity groups found to update.'
76+
77+
if __name__ == '__main__':
78+
# Initialize client object.
79+
dfp_client = dfp.DfpClient.LoadFromStorage()
80+
main(dfp_client, ACTIVITY_GROUP_ID, ADVERTISER_COMPANY_ID)

0 commit comments

Comments
 (0)