Skip to content

Commit 65223fc

Browse files
author
Nicholas Chen
committed
add v201511 for DFP
1 parent 7ebec09 commit 65223fc

File tree

238 files changed

+1751
-1145
lines changed

Some content is hidden

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

238 files changed

+1751
-1145
lines changed

ChangeLog

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
3.8.1 - 10/19/13
1+
3.10.0 - 11/17/2015
2+
* Removed support for DFP v201405 and v201408.
3+
* Removed examples for v201411.
4+
* Added support for DFP v201511.
5+
6+
3.9.0 - 10/23/2015
7+
* The AdWords BatchJobHelper has been updated and added to the core library.
8+
* Updates to add_complete_campaigns_using_batch_job.py example.
9+
* Fixed issue #85.
10+
11+
3.8.1 - 10/19/2015
212
* Added BatchJobService example for AdWords v201509.
313
* Removed GeoLocationService from AdWords v201509 because it isn't available
414
in this version.

examples/adwords/v201502/account_management/get_account_changes.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,23 +70,30 @@ def main(client):
7070
% (data['campaignId'], data['campaignChangeStatus']))
7171
if (data['campaignChangeStatus'] != 'NEW' and
7272
data['campaignChangeStatus'] != 'FIELDS_UNCHANGED'):
73-
print ' Added ad extensions: %s' % data.get('addedAdExtensions')
74-
print ' Removed ad extensions: %s' % data.get('deletedAdExtensions')
75-
print (' Added campaign criteria: %s'
76-
% data.get('addedCampaignCriteria'))
77-
print (' Removed campaign criteria: %s'
78-
% data.get('deletedCampaignCriteria'))
79-
if data.get('changedAdGroups'):
73+
if 'addedAdExtensions' in data:
74+
print ' Added ad extensions: %s' % data['addedAdExtensions']
75+
if 'removedAdExtensions' in data:
76+
print ' Removed ad extensions: %s' % data['removedAdExtensions']
77+
if 'addedCampaignCriteria' in data:
78+
print (' Added campaign criteria: %s' %
79+
data['addedCampaignCriteria'])
80+
if 'removedCampaignCriteria' in data:
81+
print (' Removed campaign criteria: %s' %
82+
data['removedCampaignCriteria'])
83+
if 'changedAdGroups' in data:
8084
for ad_group_data in data['changedAdGroups']:
8185
print (' Ad group with id \'%s\' has change status \'%s\'.'
8286
% (ad_group_data['adGroupId'],
8387
ad_group_data['adGroupChangeStatus']))
8488
if ad_group_data['adGroupChangeStatus'] != 'NEW':
85-
print ' Changed ads: %s' % ad_group_data['changedAds']
86-
print (' Changed criteria: %s'
87-
% ad_group_data['changedCriteria'])
88-
print (' Removed criteria: %s'
89-
% ad_group_data['deletedCriteria'])
89+
if 'changedAds' in ad_group_data:
90+
print ' Changed ads: %s' % ad_group_data['changedAds']
91+
if 'changedCriteria' in ad_group_data:
92+
print (' Changed criteria: %s' %
93+
ad_group_data['changedCriteria'])
94+
if 'removedCriteria' in ad_group_data:
95+
print (' Removed criteria: %s' %
96+
ad_group_data['removedCriteria'])
9097
else:
9198
print 'No changes were found.'
9299

examples/adwords/v201506/account_management/get_account_changes.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,23 +70,30 @@ def main(client):
7070
% (data['campaignId'], data['campaignChangeStatus']))
7171
if (data['campaignChangeStatus'] != 'NEW' and
7272
data['campaignChangeStatus'] != 'FIELDS_UNCHANGED'):
73-
print ' Added ad extensions: %s' % data.get('addedAdExtensions')
74-
print ' Removed ad extensions: %s' % data.get('deletedAdExtensions')
75-
print (' Added campaign criteria: %s'
76-
% data.get('addedCampaignCriteria'))
77-
print (' Removed campaign criteria: %s'
78-
% data.get('deletedCampaignCriteria'))
79-
if data.get('changedAdGroups'):
73+
if 'addedAdExtensions' in data:
74+
print ' Added ad extensions: %s' % data['addedAdExtensions']
75+
if 'removedAdExtensions' in data:
76+
print ' Removed ad extensions: %s' % data['removedAdExtensions']
77+
if 'addedCampaignCriteria' in data:
78+
print (' Added campaign criteria: %s' %
79+
data['addedCampaignCriteria'])
80+
if 'removedCampaignCriteria' in data:
81+
print (' Removed campaign criteria: %s' %
82+
data['removedCampaignCriteria'])
83+
if 'changedAdGroups' in data:
8084
for ad_group_data in data['changedAdGroups']:
8185
print (' Ad group with id \'%s\' has change status \'%s\'.'
8286
% (ad_group_data['adGroupId'],
8387
ad_group_data['adGroupChangeStatus']))
8488
if ad_group_data['adGroupChangeStatus'] != 'NEW':
85-
print ' Changed ads: %s' % ad_group_data['changedAds']
86-
print (' Changed criteria: %s'
87-
% ad_group_data['changedCriteria'])
88-
print (' Removed criteria: %s'
89-
% ad_group_data['deletedCriteria'])
89+
if 'changedAds' in ad_group_data:
90+
print ' Changed ads: %s' % ad_group_data['changedAds']
91+
if 'changedCriteria' in ad_group_data:
92+
print (' Changed criteria: %s' %
93+
ad_group_data['changedCriteria'])
94+
if 'removedCriteria' in ad_group_data:
95+
print (' Removed criteria: %s' %
96+
ad_group_data['removedCriteria'])
9097
else:
9198
print 'No changes were found.'
9299

examples/adwords/v201509/account_management/get_account_changes.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,23 +70,30 @@ def main(client):
7070
% (data['campaignId'], data['campaignChangeStatus']))
7171
if (data['campaignChangeStatus'] != 'NEW' and
7272
data['campaignChangeStatus'] != 'FIELDS_UNCHANGED'):
73-
print ' Added ad extensions: %s' % data.get('addedAdExtensions')
74-
print ' Removed ad extensions: %s' % data.get('deletedAdExtensions')
75-
print (' Added campaign criteria: %s'
76-
% data.get('addedCampaignCriteria'))
77-
print (' Removed campaign criteria: %s'
78-
% data.get('deletedCampaignCriteria'))
79-
if data.get('changedAdGroups'):
73+
if 'addedAdExtensions' in data:
74+
print ' Added ad extensions: %s' % data['addedAdExtensions']
75+
if 'removedAdExtensions' in data:
76+
print ' Removed ad extensions: %s' % data['removedAdExtensions']
77+
if 'addedCampaignCriteria' in data:
78+
print (' Added campaign criteria: %s' %
79+
data['addedCampaignCriteria'])
80+
if 'removedCampaignCriteria' in data:
81+
print (' Removed campaign criteria: %s' %
82+
data['removedCampaignCriteria'])
83+
if 'changedAdGroups' in data:
8084
for ad_group_data in data['changedAdGroups']:
8185
print (' Ad group with id \'%s\' has change status \'%s\'.'
8286
% (ad_group_data['adGroupId'],
8387
ad_group_data['adGroupChangeStatus']))
8488
if ad_group_data['adGroupChangeStatus'] != 'NEW':
85-
print ' Changed ads: %s' % ad_group_data['changedAds']
86-
print (' Changed criteria: %s'
87-
% ad_group_data['changedCriteria'])
88-
print (' Removed criteria: %s'
89-
% ad_group_data['deletedCriteria'])
89+
if 'changedAds' in ad_group_data:
90+
print ' Changed ads: %s' % ad_group_data['changedAds']
91+
if 'changedCriteria' in ad_group_data:
92+
print (' Changed criteria: %s' %
93+
ad_group_data['changedCriteria'])
94+
if 'removedCriteria' in ad_group_data:
95+
print (' Removed criteria: %s' %
96+
ad_group_data['removedCriteria'])
9097
else:
9198
print 'No changes were found.'
9299

examples/adwords/v201509/campaign_management/add_complete_campaigns_using_batch_job.py

Lines changed: 31 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,10 @@
2929
import uuid
3030

3131

32-
from batch_job_util import BatchJobHelper
33-
from batch_job_util import BatchJobServiceIdGenerator
3432
from googleads import adwords
3533

3634

37-
# Set logging configuration
35+
# Set logging configuration.
3836
logging.basicConfig(level=logging.INFO)
3937
logging.getLogger('suds.transport').setLevel(logging.DEBUG)
4038

@@ -47,22 +45,36 @@
4745

4846

4947
def main(client, number_of_campaigns, number_of_adgroups, number_of_keywords):
50-
# Initialize BatchJobHelper
51-
batch_job_helper = BatchJobHelper(client)
48+
# Initialize BatchJobHelper.
49+
batch_job_helper = client.GetBatchJobHelper()
5250

51+
# Create a BatchJob.
5352
batch_job = AddBatchJob(client)
53+
# Retrieve the URL used to upload the BatchJob operations.
5454
upload_url = batch_job['uploadUrl']['url']
5555
batch_job_id = batch_job['id']
56-
5756
logging.info('Created BatchJob with ID "%d", status "%s", and upload URL '
5857
'"%s"', batch_job['id'], batch_job['status'], upload_url)
5958

60-
operations = BuildUploadUrlOperations(batch_job_helper, number_of_campaigns,
61-
number_of_adgroups, number_of_keywords)
59+
# Generate operations to upload.
60+
budget_operations = BuildBudgetOperations(batch_job_helper)
61+
campaign_operations = BuildCampaignOperations(
62+
batch_job_helper, budget_operations, number_of_campaigns)
63+
campaign_criterion_operations = BuildCampaignCriterionOperations(
64+
campaign_operations)
65+
adgroup_operations = BuildAdGroupOperations(
66+
batch_job_helper, campaign_operations, number_of_adgroups)
67+
adgroup_criterion_operations = BuildAdGroupCriterionOperations(
68+
adgroup_operations, number_of_keywords)
69+
adgroup_ad_operations = BuildAdGroupAdOperations(adgroup_operations)
6270

71+
# Upload operations.
6372
batch_job_helper.UploadBatchJobOperations(
64-
upload_url, *operations)
73+
upload_url, budget_operations, campaign_operations,
74+
campaign_criterion_operations, adgroup_operations,
75+
adgroup_criterion_operations, adgroup_ad_operations)
6576

77+
# Download and display results.
6678
download_url = GetBatchJobDownloadUrlWhenReady(client, batch_job_id)
6779
response = urllib2.urlopen(download_url)
6880
logging.info('Downloaded following response:\n%s', response.read())
@@ -79,7 +91,7 @@ def AddBatchJob(client):
7991
"""
8092
# Initialize appropriate service.
8193
batch_job_service = client.GetService('BatchJobService', version='v201509')
82-
# Create a BatchJob
94+
# Create a BatchJob.
8395
batch_job_operations = [{
8496
'operand': {},
8597
'operator': 'ADD'
@@ -160,7 +172,7 @@ def BuildAdGroupCriterionOperations(adgroup_operations, number_of_keywords=1):
160172
return criterion_operations
161173

162174

163-
def BuildAdGroupOperations(batch_id_generator,
175+
def BuildAdGroupOperations(batch_job_helper,
164176
campaign_operations, number_of_adgroups=1):
165177
"""Builds the operations adding desired number of AdGroups to given Campaigns.
166178
@@ -169,7 +181,7 @@ def BuildAdGroupOperations(batch_id_generator,
169181
BatchJobService.
170182
171183
Args:
172-
batch_id_generator: a BatchJobServiceIdGenerator instance.
184+
batch_job_helper: a BatchJobHelper instance.
173185
campaign_operations: a list containing the operations that will add
174186
Campaigns.
175187
number_of_adgroups: an int defining the number of AdGroups to be created per
@@ -189,7 +201,7 @@ def BuildAdGroupOperations(batch_id_generator,
189201
'xsi_type': 'AdGroupOperation',
190202
'operand': {
191203
'campaignId': campaign_operation['operand']['id'],
192-
'id': batch_id_generator.GetId(),
204+
'id': batch_job_helper.GetId(),
193205
'name': 'Batch Ad Group #%s' % uuid.uuid4(),
194206
'biddingStrategyConfiguration': {
195207
'bids': [
@@ -210,15 +222,15 @@ def BuildAdGroupOperations(batch_id_generator,
210222
return adgroup_operations
211223

212224

213-
def BuildBudgetOperations(batch_id_generator):
225+
def BuildBudgetOperations(batch_job_helper):
214226
"""Builds the operations needed to create a new Budget.
215227
216228
Note: When the Budget is created, it will have a different Id than the one
217229
generated here as a temporary Id. This is just used to identify it in the
218230
BatchJobService.
219231
220232
Args:
221-
batch_id_generator: a BatchJobServiceIdGenerator instance.
233+
batch_job_helper: a BatchJobHelper instance.
222234
223235
Returns:
224236
a list containing the operation that will create a new Budget.
@@ -234,7 +246,7 @@ def BuildBudgetOperations(batch_id_generator):
234246
'name': 'Batch budget #%s' % uuid.uuid4(),
235247
# This is a temporary Id used by the BatchJobService to identify the
236248
# Budget for operations that require a budgetId.
237-
'budgetId': batch_id_generator.GetId(),
249+
'budgetId': batch_job_helper.GetId(),
238250
'amount': {
239251
'microAmount': '50000000'
240252
},
@@ -282,7 +294,7 @@ def BuildCampaignCriterionOperations(campaign_operations):
282294
return criterion_operations
283295

284296

285-
def BuildCampaignOperations(batch_id_generator,
297+
def BuildCampaignOperations(batch_job_helper,
286298
budget_operations, number_of_campaigns=1):
287299
"""Builds the operations needed to create a new Campaign.
288300
@@ -291,7 +303,7 @@ def BuildCampaignOperations(batch_id_generator,
291303
BatchJobService.
292304
293305
Args:
294-
batch_id_generator: a BatchJobServiceIdGenerator instance.
306+
batch_job_helper: a BatchJobHelper instance.
295307
budget_operations: a list containing the operation that will add the budget
296308
used by these Campaigns.
297309
number_of_campaigns: an int number defining the number of campaigns to be
@@ -316,7 +328,7 @@ def BuildCampaignOperations(batch_id_generator,
316328
'status': 'PAUSED',
317329
# This is a temporary Id used by the BatchJobService to identify
318330
# the Campaigns for operations that require a campaignId.
319-
'id': batch_id_generator.GetId(),
331+
'id': batch_job_helper.GetId(),
320332
'advertisingChannelType': 'SEARCH',
321333
# Note that only the budgetId is required
322334
'budget': {
@@ -333,70 +345,6 @@ def BuildCampaignOperations(batch_id_generator,
333345
return campaign_operations
334346

335347

336-
def BuildUploadUrlOperations(batch_job_helper, number_of_campaigns,
337-
number_of_adgroups, number_of_keywords):
338-
"""Builds a list of operations that will be uploaded to the BatchJobService.
339-
340-
Args:
341-
batch_job_helper: a BatchJobHelper instance used to construct operations.
342-
number_of_campaigns: an int defining the number of Campaigns to be created.
343-
number_of_adgroups: an int defining the number of AdGroups to be created.
344-
number_of_keywords: an int defining the number of Keywords to be created.
345-
346-
Returns:
347-
A tuple of str, where each is a set of operations for distinct services.
348-
"""
349-
# Initialize BatchJobServiceIdGenerator.
350-
batch_id_generator = BatchJobServiceIdGenerator()
351-
352-
# Build BudgetOperations and retrieve in XML form.
353-
budget_operations = BuildBudgetOperations(batch_id_generator)
354-
budget_request_xml = batch_job_helper.GenerateRawRequestXML(
355-
budget_operations, 'BudgetService')
356-
budget_operations_xml = batch_job_helper.ExtractOperations(
357-
budget_request_xml)
358-
# Build CampaignOperations and retrieve in XML form.
359-
campaign_operations = BuildCampaignOperations(
360-
batch_id_generator, budget_operations, number_of_campaigns)
361-
campaign_request_xml = batch_job_helper.GenerateRawRequestXML(
362-
campaign_operations, 'CampaignService')
363-
campaign_operations_xml = batch_job_helper.ExtractOperations(
364-
campaign_request_xml)
365-
# Build CampaignCriterionOperations and retrieve in XML form.
366-
campaign_criterion_operations = BuildCampaignCriterionOperations(
367-
campaign_operations)
368-
campaign_criterion_request_xml = batch_job_helper.GenerateRawRequestXML(
369-
campaign_criterion_operations, 'CampaignCriterionService')
370-
campaign_criterion_operations_xml = (
371-
batch_job_helper.ExtractOperations(
372-
campaign_criterion_request_xml))
373-
# Build AdGroupOperations and retrieve in XML form.
374-
adgroup_operations = BuildAdGroupOperations(
375-
batch_id_generator, campaign_operations, number_of_adgroups)
376-
adgroup_request_xml = batch_job_helper.GenerateRawRequestXML(
377-
adgroup_operations, 'AdGroupService')
378-
adgroup_operations_xml = batch_job_helper.ExtractOperations(
379-
adgroup_request_xml)
380-
# Build AdGroupCriterionOperations and retrieve in XML form.
381-
adgroup_criterion_operations = BuildAdGroupCriterionOperations(
382-
adgroup_operations, number_of_keywords)
383-
adgroup_criterion_request_xml = batch_job_helper.GenerateRawRequestXML(
384-
adgroup_criterion_operations, 'AdGroupCriterionService')
385-
adgroup_criterion_operations_xml = (
386-
batch_job_helper.ExtractOperations(
387-
adgroup_criterion_request_xml))
388-
# Build AdGroupAdOperations and retrieve in XML form.
389-
adgroup_ad_operations = BuildAdGroupAdOperations(adgroup_operations)
390-
adgroup_ad_request_xml = batch_job_helper.GenerateRawRequestXML(
391-
adgroup_ad_operations, 'AdGroupAdService')
392-
adgroup_ad_operations_xml = batch_job_helper.ExtractOperations(
393-
adgroup_ad_request_xml)
394-
395-
return (budget_operations_xml, campaign_operations_xml,
396-
campaign_criterion_operations_xml, adgroup_operations_xml,
397-
adgroup_criterion_operations_xml, adgroup_ad_operations_xml)
398-
399-
400348
def GetBatchJob(client, batch_job_id):
401349
"""Retrieves the BatchJob with the given id.
402350

0 commit comments

Comments
 (0)