google-adwords-api 0.8.2 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. data/ChangeLog +6 -0
  2. data/README +3 -3
  3. data/examples/{v201206/basic_operations/delete_ad_group.rb → v201209/adwords_for_video/add_video_campaign.rb} +41 -40
  4. data/examples/{v201206/basic_operations/pause_ad.rb → v201209/adwords_for_video/find_videos.rb} +33 -25
  5. data/examples/{v201206/basic_operations/get_keywords.rb → v201209/adwords_for_video/get_keyword_criteria.rb} +24 -27
  6. data/examples/{v201206/basic_operations/get_campaigns_with_awql.rb → v201209/adwords_for_video/get_targeting_groups.rb} +26 -18
  7. data/examples/{v201206/basic_operations/get_ad_groups.rb → v201209/adwords_for_video/get_video_campaign_criteria.rb} +22 -21
  8. data/examples/v201209/adwords_for_video/get_video_campaign_stats.rb +126 -0
  9. data/examples/{v201206/basic_operations/get_campaigns.rb → v201209/adwords_for_video/get_video_campaigns.rb} +16 -15
  10. data/examples/v201302/advanced_operations/create_and_attach_shared_keyword_set.rb +139 -0
  11. data/examples/v201302/advanced_operations/find_and_remove_criteria_from_shared_set.rb +173 -0
  12. data/lib/adwords_api/api_config.rb +17 -59
  13. data/lib/adwords_api/report_utils.rb +3 -19
  14. data/lib/adwords_api/{v201206/ad_param_service.rb → v201209/video_ad_service.rb} +8 -8
  15. data/lib/adwords_api/v201209/video_ad_service_registry.rb +46 -0
  16. data/lib/adwords_api/{v201206/campaign_ad_extension_service.rb → v201209/video_campaign_criterion_service.rb} +8 -8
  17. data/lib/adwords_api/v201209/video_campaign_criterion_service_registry.rb +47 -0
  18. data/lib/adwords_api/{v201206/bulk_mutate_job_service.rb → v201209/video_campaign_service.rb} +8 -8
  19. data/lib/adwords_api/v201209/video_campaign_service_registry.rb +46 -0
  20. data/lib/adwords_api/v201209/video_service.rb +42 -0
  21. data/lib/adwords_api/v201209/video_service_registry.rb +46 -0
  22. data/lib/adwords_api/{v201206/ad_group_ad_service.rb → v201209/video_targeting_group_criterion_service.rb} +8 -12
  23. data/lib/adwords_api/v201209/video_targeting_group_criterion_service_registry.rb +46 -0
  24. data/lib/adwords_api/{v201206/ad_extension_override_service.rb → v201209/video_targeting_group_service.rb} +8 -8
  25. data/lib/adwords_api/v201209/video_targeting_group_service_registry.rb +46 -0
  26. data/lib/adwords_api/v201302/ad_group_feed_service.rb +1 -1
  27. data/lib/adwords_api/v201302/ad_group_feed_service_registry.rb +2 -2
  28. data/lib/adwords_api/v201302/campaign_feed_service.rb +1 -1
  29. data/lib/adwords_api/v201302/campaign_feed_service_registry.rb +2 -2
  30. data/lib/adwords_api/v201302/feed_item_service.rb +1 -1
  31. data/lib/adwords_api/v201302/feed_item_service_registry.rb +3 -4
  32. data/lib/adwords_api/v201302/feed_service.rb +1 -1
  33. data/lib/adwords_api/v201302/feed_service_registry.rb +4 -5
  34. data/lib/adwords_api/{v201206/user_list_service.rb → v201302/shared_set_service.rb} +9 -9
  35. data/lib/adwords_api/v201302/shared_set_service_registry.rb +47 -0
  36. data/lib/adwords_api/version.rb +1 -1
  37. data/test/adwords_api/test_report_utils.rb +0 -89
  38. data/test/examples/v201302/test_advanced_operations.rb +10 -0
  39. data/test/templates/v201209/basic_operations_get_campaigns.def +1 -1
  40. data/test/templates/v201302/basic_operations_get_campaigns.def +1 -1
  41. data/test/templates/v201302/misc_use_oauth2_jwt.def +131 -0
  42. data/test/test_utils.rb +6 -2
  43. metadata +26 -121
  44. data/examples/v201206/account_management/create_account.rb +0 -87
  45. data/examples/v201206/account_management/get_account_alerts.rb +0 -114
  46. data/examples/v201206/account_management/get_account_changes.rb +0 -137
  47. data/examples/v201206/account_management/get_account_hierarchy.rb +0 -95
  48. data/examples/v201206/account_management/get_client_customer_id.rb +0 -88
  49. data/examples/v201206/account_management/get_client_unit_usage.rb +0 -90
  50. data/examples/v201206/basic_operations/add_ad_groups.rb +0 -136
  51. data/examples/v201206/basic_operations/add_campaigns.rb +0 -151
  52. data/examples/v201206/basic_operations/add_keywords.rb +0 -108
  53. data/examples/v201206/basic_operations/add_text_ads.rb +0 -105
  54. data/examples/v201206/basic_operations/delete_ad.rb +0 -85
  55. data/examples/v201206/basic_operations/delete_campaign.rb +0 -103
  56. data/examples/v201206/basic_operations/delete_keyword.rb +0 -90
  57. data/examples/v201206/basic_operations/get_text_ads.rb +0 -106
  58. data/examples/v201206/basic_operations/update_ad_group.rb +0 -81
  59. data/examples/v201206/basic_operations/update_campaign.rb +0 -84
  60. data/examples/v201206/basic_operations/update_keyword.rb +0 -99
  61. data/examples/v201206/campaign_management/add_experiment.rb +0 -158
  62. data/examples/v201206/campaign_management/add_keywords_in_bulk.rb +0 -150
  63. data/examples/v201206/campaign_management/add_location_extension.rb +0 -117
  64. data/examples/v201206/campaign_management/add_location_extension_override.rb +0 -83
  65. data/examples/v201206/campaign_management/get_all_disapproved_ads.rb +0 -93
  66. data/examples/v201206/campaign_management/get_all_disapproved_ads_with_awql.rb +0 -84
  67. data/examples/v201206/campaign_management/promote_experiment.rb +0 -77
  68. data/examples/v201206/campaign_management/set_ad_parameters.rb +0 -114
  69. data/examples/v201206/campaign_management/validate_text_ad.rb +0 -106
  70. data/examples/v201206/error_handling/handle_captcha_challenge.rb +0 -93
  71. data/examples/v201206/error_handling/handle_partial_failures.rb +0 -126
  72. data/examples/v201206/error_handling/handle_policy_violation_error.rb +0 -137
  73. data/examples/v201206/error_handling/handle_two_factor_authorization_error.rb +0 -88
  74. data/examples/v201206/misc/get_all_images_and_videos.rb +0 -100
  75. data/examples/v201206/misc/upload_image.rb +0 -89
  76. data/examples/v201206/misc/use_oauth2.rb +0 -97
  77. data/examples/v201206/optimization/estimate_keyword_traffic.rb +0 -129
  78. data/examples/v201206/optimization/get_keyword_bid_simulations.rb +0 -92
  79. data/examples/v201206/optimization/get_keyword_ideas.rb +0 -114
  80. data/examples/v201206/optimization/get_placement_ideas.rb +0 -104
  81. data/examples/v201206/remarketing/add_audience.rb +0 -115
  82. data/examples/v201206/remarketing/add_conversion_tracker.rb +0 -97
  83. data/examples/v201206/reporting/download_criteria_report.rb +0 -79
  84. data/examples/v201206/reporting/download_criteria_report_with_awql.rb +0 -78
  85. data/examples/v201206/reporting/get_campaign_stats.rb +0 -105
  86. data/examples/v201206/reporting/get_report_fields.rb +0 -71
  87. data/examples/v201206/reporting/parallel_report_download.rb +0 -162
  88. data/examples/v201206/targeting/add_campaign_targeting_criteria.rb +0 -118
  89. data/examples/v201206/targeting/get_campaign_targeting_criteria.rb +0 -102
  90. data/examples/v201206/targeting/get_targetable_languages_and_carriers.rb +0 -86
  91. data/examples/v201206/targeting/lookup_location.rb +0 -104
  92. data/lib/adwords_api/v201206/ad_extension_override_service_registry.rb +0 -46
  93. data/lib/adwords_api/v201206/ad_group_ad_service_registry.rb +0 -46
  94. data/lib/adwords_api/v201206/ad_group_criterion_service.rb +0 -42
  95. data/lib/adwords_api/v201206/ad_group_criterion_service_registry.rb +0 -46
  96. data/lib/adwords_api/v201206/ad_group_service.rb +0 -42
  97. data/lib/adwords_api/v201206/ad_group_service_registry.rb +0 -46
  98. data/lib/adwords_api/v201206/ad_param_service_registry.rb +0 -46
  99. data/lib/adwords_api/v201206/alert_service.rb +0 -34
  100. data/lib/adwords_api/v201206/alert_service_registry.rb +0 -46
  101. data/lib/adwords_api/v201206/budget_order_service.rb +0 -42
  102. data/lib/adwords_api/v201206/budget_order_service_registry.rb +0 -46
  103. data/lib/adwords_api/v201206/bulk_mutate_job_service_registry.rb +0 -46
  104. data/lib/adwords_api/v201206/campaign_ad_extension_service_registry.rb +0 -46
  105. data/lib/adwords_api/v201206/campaign_criterion_service.rb +0 -42
  106. data/lib/adwords_api/v201206/campaign_criterion_service_registry.rb +0 -46
  107. data/lib/adwords_api/v201206/campaign_service.rb +0 -42
  108. data/lib/adwords_api/v201206/campaign_service_registry.rb +0 -46
  109. data/lib/adwords_api/v201206/constant_data_service.rb +0 -62
  110. data/lib/adwords_api/v201206/constant_data_service_registry.rb +0 -46
  111. data/lib/adwords_api/v201206/conversion_tracker_service.rb +0 -38
  112. data/lib/adwords_api/v201206/conversion_tracker_service_registry.rb +0 -46
  113. data/lib/adwords_api/v201206/customer_service.rb +0 -34
  114. data/lib/adwords_api/v201206/customer_service_registry.rb +0 -46
  115. data/lib/adwords_api/v201206/customer_sync_service.rb +0 -34
  116. data/lib/adwords_api/v201206/customer_sync_service_registry.rb +0 -47
  117. data/lib/adwords_api/v201206/data_service.rb +0 -38
  118. data/lib/adwords_api/v201206/data_service_registry.rb +0 -46
  119. data/lib/adwords_api/v201206/experiment_service.rb +0 -38
  120. data/lib/adwords_api/v201206/experiment_service_registry.rb +0 -46
  121. data/lib/adwords_api/v201206/geo_location_service.rb +0 -34
  122. data/lib/adwords_api/v201206/geo_location_service_registry.rb +0 -46
  123. data/lib/adwords_api/v201206/info_service.rb +0 -34
  124. data/lib/adwords_api/v201206/info_service_registry.rb +0 -46
  125. data/lib/adwords_api/v201206/location_criterion_service.rb +0 -34
  126. data/lib/adwords_api/v201206/location_criterion_service_registry.rb +0 -46
  127. data/lib/adwords_api/v201206/managed_customer_service.rb +0 -38
  128. data/lib/adwords_api/v201206/managed_customer_service_registry.rb +0 -46
  129. data/lib/adwords_api/v201206/media_service.rb +0 -38
  130. data/lib/adwords_api/v201206/media_service_registry.rb +0 -46
  131. data/lib/adwords_api/v201206/mutate_job_service.rb +0 -42
  132. data/lib/adwords_api/v201206/mutate_job_service_registry.rb +0 -46
  133. data/lib/adwords_api/v201206/report_definition_service.rb +0 -34
  134. data/lib/adwords_api/v201206/report_definition_service_registry.rb +0 -46
  135. data/lib/adwords_api/v201206/targeting_idea_service.rb +0 -38
  136. data/lib/adwords_api/v201206/targeting_idea_service_registry.rb +0 -46
  137. data/lib/adwords_api/v201206/traffic_estimator_service.rb +0 -34
  138. data/lib/adwords_api/v201206/traffic_estimator_service_registry.rb +0 -46
  139. data/lib/adwords_api/v201206/user_list_service_registry.rb +0 -46
  140. data/test/examples/v201206/test_account_management.rb +0 -60
  141. data/test/examples/v201206/test_basic_operations.rb +0 -177
  142. data/test/examples/v201206/test_campaign_management.rb +0 -124
  143. data/test/examples/v201206/test_error_handling.rb +0 -63
  144. data/test/examples/v201206/test_misc.rb +0 -39
  145. data/test/examples/v201206/test_optimization.rb +0 -63
  146. data/test/examples/v201206/test_remarketing.rb +0 -39
  147. data/test/examples/v201206/test_reporting.rb +0 -84
  148. data/test/examples/v201206/test_targeting.rb +0 -60
  149. data/test/examples/v201206/utils.rb +0 -244
  150. data/test/suite_exampletests_v201206.rb +0 -37
data/ChangeLog CHANGED
@@ -1,3 +1,9 @@
1
+ 0.9.0:
2
+ - Shared set support and examples (beta feature).
3
+ - Updated feed services auto-generated code.
4
+ - AdWords for Video API support and examples (beta feature).
5
+ - Removed deprecated API version v201206.
6
+
1
7
  0.8.2:
2
8
  - Support and examples for v201302.
3
9
 
data/README CHANGED
@@ -3,7 +3,7 @@
3
3
  Welcome to the next generation Google-developed Ruby client library for the
4
4
  AdWords and DoubleClick Ad Exchange Buyer API!
5
5
 
6
- It contains full support for v201206 and v201209, with full stubs, and a
6
+ It contains full support for v201209 and v201302, with full stubs, and a
7
7
  simplified programming interface that lets you handle everything in native
8
8
  Ruby collections.
9
9
 
@@ -58,7 +58,7 @@ You can also pass API a manually constructed config hash like:
58
58
  })
59
59
 
60
60
  Then, just specify which service you're looking to use, and which version:
61
- campaign_srv = adwords.service(:CampaignService, :v201209)
61
+ campaign_srv = adwords.service(:CampaignService, :v201302)
62
62
 
63
63
  and you should now be able to just use the API methods in the object you were
64
64
  returned:
@@ -200,7 +200,7 @@ Questions can be asked on forum
200
200
 
201
201
  == Licence
202
202
 
203
- Copyright 2010-2012, Google Inc. All Rights Reserved.
203
+ Copyright 2010-2013, Google Inc. All Rights Reserved.
204
204
 
205
205
  Licensed under the Apache License, Version 2.0 (the "License");
206
206
  you may not use this file except in compliance with the License.
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # Author:: api.dklimkin@gmail.com (Danial Klimkin)
5
5
  #
6
- # Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
6
+ # Copyright:: Copyright 2013, Google Inc. All Rights Reserved.
7
7
  #
8
8
  # License:: Licensed under the Apache License, Version 2.0 (the "License");
9
9
  # you may not use this file except in compliance with the License.
@@ -18,14 +18,16 @@
18
18
  # See the License for the specific language governing permissions and
19
19
  # limitations under the License.
20
20
  #
21
- # This example deletes an ad group by setting the status to 'DELETED'. To get ad
22
- # groups, run get_ad_groups.rb.
21
+ # This example illustrates how to create a video campaign.
23
22
  #
24
- # Tags: AdGroupService.mutate
23
+ # Note: AdWords for Video API is a Beta feature.
24
+ #
25
+ # Tags: VideoCampaignService.mutate, BudgetService.mutate
25
26
 
26
27
  require 'adwords_api'
28
+ require 'date'
27
29
 
28
- def delete_ad_group(ad_group_id)
30
+ def add_video_campaign()
29
31
  # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
30
32
  # when called without parameters.
31
33
  adwords = AdwordsApi::Api.new
@@ -34,55 +36,54 @@ def delete_ad_group(ad_group_id)
34
36
  # the configuration file or provide your own logger:
35
37
  # adwords.logger = Logger.new('adwords_xml.log')
36
38
 
37
- ad_group_srv = adwords.service(:AdGroupService, API_VERSION)
39
+ budget_srv = adwords.service(:BudgetService, API_VERSION)
40
+ video_campaign_srv = adwords.service(:VideoCampaignService, API_VERSION)
38
41
 
39
- # Retrieve the ad group to obtain its name. This is optional but recommended
40
- # to keep deleted objects searchable. In production the name is already known
41
- # in most cases.
42
- selector = {
43
- :fields => ['Id', 'Name'],
44
- :predicates => [
45
- {:field => 'Id', :operator => 'EQUALS', :values => [ad_group_id]}
46
- ]
42
+ # Create a budget, which can be shared by multiple campaigns.
43
+ budget = {
44
+ :name => 'Video budget #%d' % (Time.new.to_f * 1000).to_i,
45
+ :amount => {:micro_amount => 50000000},
46
+ :delivery_method => 'STANDARD',
47
+ :period => 'DAILY'
47
48
  }
48
- result = ad_group_srv.get(selector)
49
+ budget_operation = {:operator => 'ADD', :operand => budget}
49
50
 
50
- if result.nil? or result[:entries].empty?
51
- raise StandardError, "Ad group with ID %d was not found." % ad_group_id
52
- end
51
+ # Add budget.
52
+ return_budget = budget_srv.mutate([budget_operation])
53
+ budget_id = return_budget[:value].first[:budget_id]
53
54
 
54
- # We recommend renaming object on delete to avoid name conflicts later.
55
- ad_group_name = result[:entries].first[:name]
56
- ad_group_name += Time.now.strftime(" (deleted on %Y-%m-%d %H:%M:%S)")
55
+ # Create video campaign.
56
+ campaigns = [{
57
+ :name => "Interplanetary Video #%d" % (Time.new.to_f * 1000).to_i,
58
+ :status => 'PAUSED',
59
+ :budget_id => budget_id,
60
+ # Optional fields:
61
+ :start_date =>
62
+ DateTime.parse((Date.today + 1).to_s).strftime('%Y%m%d'),
63
+ }]
57
64
 
58
- # Prepare for deleting ad group.
59
- operation = {
60
- :operator => 'SET',
61
- :operand => {
62
- :id => ad_group_id,
63
- :name => ad_group_name,
64
- :status => 'DELETED'
65
- }
66
- }
65
+ # Prepare for adding campaign.
66
+ operations = campaigns.map do |campaign|
67
+ {:operator => 'ADD', :operand => campaign}
68
+ end
67
69
 
68
- # Delete ad group.
69
- response = ad_group_srv.mutate([operation])
70
+ # Add video campaign.
71
+ response = video_campaign_srv.mutate(operations)
70
72
  if response and response[:value]
71
- ad_group = response[:value].first
72
- puts "Ad group ID %d was successfully deleted and renamed to '%s'." %
73
- [ad_group[:id], ad_group[:name]]
73
+ response[:value].each do |campaign|
74
+ puts "Campaign with name '%s' and ID %d was added." %
75
+ [campaign[:name], campaign[:id]]
76
+ end
74
77
  else
75
- puts 'No ad group was updated.'
78
+ raise new StandardError, 'No campaigns were added.'
76
79
  end
77
80
  end
78
81
 
79
82
  if __FILE__ == $0
80
- API_VERSION = :v201206
83
+ API_VERSION = :v201209
81
84
 
82
85
  begin
83
- # ID of an ad group to delete.
84
- ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
85
- delete_ad_group(ad_group_id)
86
+ add_video_campaign()
86
87
 
87
88
  # HTTP errors.
88
89
  rescue AdsCommon::Errors::HttpError => e
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # Author:: api.dklimkin@gmail.com (Danial Klimkin)
5
5
  #
6
- # Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
6
+ # Copyright:: Copyright 2013, Google Inc. All Rights Reserved.
7
7
  #
8
8
  # License:: Licensed under the Apache License, Version 2.0 (the "License");
9
9
  # you may not use this file except in compliance with the License.
@@ -18,14 +18,16 @@
18
18
  # See the License for the specific language governing permissions and
19
19
  # limitations under the License.
20
20
  #
21
- # This example illustrates how to update an ad, setting its status to 'PAUSED'.
22
- # To create ads, run add_text_ads.rb.
21
+ # This example illustrates how to find YouTube videos by a search string. It
22
+ # retrieve details for the first 100 matching videos.
23
23
  #
24
- # Tags: AdGroupAdService.mutate
24
+ # Note: AdWords for Video API is a Beta feature.
25
+ #
26
+ # Tags: VideoService.search
25
27
 
26
28
  require 'adwords_api'
27
29
 
28
- def pause_ad(ad_group_id, ad_id)
30
+ def find_videos()
29
31
  # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
30
32
  # when called without parameters.
31
33
  adwords = AdwordsApi::Api.new
@@ -34,37 +36,43 @@ def pause_ad(ad_group_id, ad_id)
34
36
  # the configuration file or provide your own logger:
35
37
  # adwords.logger = Logger.new('adwords_xml.log')
36
38
 
37
- ad_group_ad_srv = adwords.service(:AdGroupAdService, API_VERSION)
39
+ video_srv = adwords.service(:VideoService, API_VERSION)
40
+
41
+ # Search string to use.
42
+ query_str = 'AdWords API with Ruby'
38
43
 
39
- # Prepare operation for updating ad.
40
- operation = {
41
- :operator => 'SET',
42
- :operand => {
43
- :ad_group_id => ad_group_id,
44
- :status => 'PAUSED',
45
- :ad => {:id => ad_id}
44
+ # Create a selector.
45
+ selector = {
46
+ :search_type => 'VIDEO',
47
+ :query => query_str,
48
+ :paging => {
49
+ :start_index => 0,
50
+ :number_results => PAGE_SIZE
46
51
  }
47
52
  }
48
53
 
49
- # Update ad.
50
- response = ad_group_ad_srv.mutate([operation])
51
- if response and response[:value]
52
- ad = response[:value].first
53
- puts "Ad ID %d was successfully updated, status set to '%s'." %
54
- [ad[:ad][:id], ad[:status]]
54
+ # Run the query.
55
+ page = video_srv.search(selector)
56
+
57
+ if page[:entries]
58
+ page[:entries].each do |video|
59
+ puts "YouTube video ID '%s' with title '%s' found." %
60
+ [video[:id], video[:title]]
61
+ end
62
+ if page.include?(:total_num_entries)
63
+ puts "\tTotal number of matching videos: %d." % [page[:total_num_entries]]
64
+ end
55
65
  else
56
- puts 'No ads were updated.'
66
+ puts "No videos matching '%s' were found." % query_str
57
67
  end
58
68
  end
59
69
 
60
70
  if __FILE__ == $0
61
- API_VERSION = :v201206
71
+ API_VERSION = :v201209
72
+ PAGE_SIZE = 100
62
73
 
63
74
  begin
64
- # IDs of ad to pause and its ad group.
65
- ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
66
- ad_id = 'INSERT_AD_ID_HERE'.to_i
67
- pause_ad(ad_group_id, ad_id)
75
+ find_videos()
68
76
 
69
77
  # HTTP errors.
70
78
  rescue AdsCommon::Errors::HttpError => e
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # Author:: api.dklimkin@gmail.com (Danial Klimkin)
5
5
  #
6
- # Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
6
+ # Copyright:: Copyright 2013, Google Inc. All Rights Reserved.
7
7
  #
8
8
  # License:: Licensed under the Apache License, Version 2.0 (the "License");
9
9
  # you may not use this file except in compliance with the License.
@@ -18,14 +18,16 @@
18
18
  # See the License for the specific language governing permissions and
19
19
  # limitations under the License.
20
20
  #
21
- # This example illustrates how to retrieve all keywords for an ad group. To add
22
- # keywords to an existing ad group, run add_keywords.rb.
21
+ # This example show how to retrieve all keywords for a video campaign. To get
22
+ # a list with all campaigns, run get_video_campaigns.rb.
23
23
  #
24
- # Tags: AdGroupCriterionService.get
24
+ # Note: AdWords for Video API is a Beta feature.
25
+ #
26
+ # Tags: VideoTargetingGroupCriterionService.get
25
27
 
26
28
  require 'adwords_api'
27
29
 
28
- def get_keywords(ad_group_id)
30
+ def get_keyword_criteria(campaign_id)
29
31
  # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
30
32
  # when called without parameters.
31
33
  adwords = AdwordsApi::Api.new
@@ -34,19 +36,13 @@ def get_keywords(ad_group_id)
34
36
  # the configuration file or provide your own logger:
35
37
  # adwords.logger = Logger.new('adwords_xml.log')
36
38
 
37
- ad_group_criterion_srv =
38
- adwords.service(:AdGroupCriterionService, API_VERSION)
39
+ vtgc_srv =
40
+ adwords.service(:VideoTargetingGroupCriterionService, API_VERSION)
39
41
 
40
- # Get all keywords for this ad group.
42
+ # Get all the keywords for the campaign.
41
43
  selector = {
42
- :fields => ['Id', 'CriteriaType', 'KeywordText'],
43
- :ordering => [
44
- {:field => 'Id', :sort_order => 'ASCENDING'}
45
- ],
46
- :predicates => [
47
- {:field => 'AdGroupId', :operator => 'EQUALS', :values => [ad_group_id]},
48
- {:field => 'CriteriaType', :operator => 'EQUALS', :values => ['KEYWORD']}
49
- ],
44
+ :campaign_ids => [campaign_id],
45
+ :criterion_types => ['SEARCH_KEYWORD'],
50
46
  :paging => {
51
47
  :start_index => 0,
52
48
  :number_results => PAGE_SIZE
@@ -57,13 +53,15 @@ def get_keywords(ad_group_id)
57
53
  offset, page = 0, {}
58
54
 
59
55
  begin
60
- page = ad_group_criterion_srv.get(selector)
56
+ page = vtgc_srv.get(selector)
61
57
  if page[:entries]
62
58
  page[:entries].each do |keyword|
63
- puts "Keyword ID %d, type '%s' and text '%s'" %
64
- [keyword[:criterion][:id],
65
- keyword[:criterion][:type],
66
- keyword[:criterion][:text]]
59
+ negative_string =
60
+ ('NegativeTargetingGroupCriterion'.eql?(keyword[:xsi_type])) ?
61
+ ' (negative)' : ''
62
+ puts "Criterion%s ID %d, targeting group ID %d and text '%s'" %
63
+ [negative_string, keyword[:criterion][:id],
64
+ keyword[:targeting_group_id], keyword[:criterion][:text]]
67
65
  end
68
66
  # Increment values to request the next page.
69
67
  offset += PAGE_SIZE
@@ -72,19 +70,18 @@ def get_keywords(ad_group_id)
72
70
  end while page[:total_num_entries] > offset
73
71
 
74
72
  if page.include?(:total_num_entries)
75
- puts "\tAd group ID %d has %d keyword(s)." %
76
- [ad_group_id, page[:total_num_entries]]
73
+ puts "\tTotal number of keywords found: %d." % [page[:total_num_entries]]
77
74
  end
78
75
  end
79
76
 
80
77
  if __FILE__ == $0
81
- API_VERSION = :v201206
78
+ API_VERSION = :v201209
82
79
  PAGE_SIZE = 500
83
80
 
84
81
  begin
85
- # Ad group ID to get keywords for.
86
- ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
87
- get_keywords(ad_group_id)
82
+ # Campaign ID to get criteria for.
83
+ campaign_id = 'INSERT_CAMPAIGN_ID_HERE'.to_i
84
+ get_keyword_criteria(campaign_id)
88
85
 
89
86
  # HTTP errors.
90
87
  rescue AdsCommon::Errors::HttpError => e
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # Author:: api.dklimkin@gmail.com (Danial Klimkin)
5
5
  #
6
- # Copyright:: Copyright 2012, Google Inc. All Rights Reserved.
6
+ # Copyright:: Copyright 2013, Google Inc. All Rights Reserved.
7
7
  #
8
8
  # License:: Licensed under the Apache License, Version 2.0 (the "License");
9
9
  # you may not use this file except in compliance with the License.
@@ -18,14 +18,15 @@
18
18
  # See the License for the specific language governing permissions and
19
19
  # limitations under the License.
20
20
  #
21
- # This example illustrates how to retrieve all the campaigns for an account with
22
- # AWQL.
21
+ # This example show how to retrieve all targeting groups for an account.
23
22
  #
24
- # Tags: CampaignService.query
23
+ # Note: AdWords for Video API is a Beta feature.
24
+ #
25
+ # Tags: VideoTargetingGroupService.get
25
26
 
26
27
  require 'adwords_api'
27
28
 
28
- def get_campaigns_with_awql()
29
+ def get_targeting_groups()
29
30
  # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
30
31
  # when called without parameters.
31
32
  adwords = AdwordsApi::Api.new
@@ -34,46 +35,53 @@ def get_campaigns_with_awql()
34
35
  # the configuration file or provide your own logger:
35
36
  # adwords.logger = Logger.new('adwords_xml.log')
36
37
 
37
- campaign_srv = adwords.service(:CampaignService, API_VERSION)
38
+ video_targeting_group_srv =
39
+ adwords.service(:VideoTargetingGroupService, API_VERSION)
38
40
 
39
- # Get all the campaigns for this account.
40
- query = 'SELECT Id, Name, Status ORDER BY Name'
41
+ # Get all targeting groups for this account.
42
+ selector = {
43
+ :paging => {
44
+ :start_index => 0,
45
+ :number_results => PAGE_SIZE
46
+ }
47
+ }
41
48
 
42
49
  # Set initial values.
43
50
  offset, page = 0, {}
44
51
 
45
52
  begin
46
- page_query = query + ' LIMIT %d,%d' % [offset, PAGE_SIZE]
47
- page = campaign_srv.query(page_query)
53
+ page = video_targeting_group_srv.get(selector)
48
54
  if page[:entries]
49
- page[:entries].each do |campaign|
50
- puts "Campaign ID %d, name '%s' and status '%s'" %
51
- [campaign[:id], campaign[:name], campaign[:status]]
55
+ page[:entries].each do |group|
56
+ puts "Targeting group ID %d, campaign ID %d and name '%s'" %
57
+ [group[:id], group[:campaign_id], group[:name]]
52
58
  end
53
59
  # Increment values to request the next page.
54
60
  offset += PAGE_SIZE
61
+ selector[:paging][:start_index] = offset
55
62
  end
56
63
  end while page[:total_num_entries] > offset
57
64
 
58
65
  if page.include?(:total_num_entries)
59
- puts "\tTotal number of campaigns found: %d." % page[:total_num_entries]
66
+ puts "\tTotal number of targeting groups found: %d." %
67
+ [page[:total_num_entries]]
60
68
  end
61
69
  end
62
70
 
63
71
  if __FILE__ == $0
64
- API_VERSION = :v201206
72
+ API_VERSION = :v201209
65
73
  PAGE_SIZE = 500
66
74
 
67
75
  begin
68
- get_campaigns_with_awql()
76
+ get_targeting_groups()
69
77
 
70
78
  # HTTP errors.
71
79
  rescue AdsCommon::Errors::HttpError => e
72
- puts 'HTTP Error: %s' % e
80
+ puts "HTTP Error: %s" % e
73
81
 
74
82
  # API errors.
75
83
  rescue AdwordsApi::Errors::ApiException => e
76
- puts 'Message: %s' % e.message
84
+ puts "Message: %s" % e.message
77
85
  puts 'Errors:'
78
86
  e.errors.each_with_index do |error, index|
79
87
  puts "\tError [%d]:" % (index + 1)
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # Author:: api.dklimkin@gmail.com (Danial Klimkin)
5
5
  #
6
- # Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
6
+ # Copyright:: Copyright 2013, Google Inc. All Rights Reserved.
7
7
  #
8
8
  # License:: Licensed under the Apache License, Version 2.0 (the "License");
9
9
  # you may not use this file except in compliance with the License.
@@ -18,14 +18,15 @@
18
18
  # See the License for the specific language governing permissions and
19
19
  # limitations under the License.
20
20
  #
21
- # This example illustrates how to retrieve all the ad groups for a campaign. To
22
- # create an ad group, run add_ad_group.rb.
21
+ # This example demonstrates how to retrieve all campaign-level criteria.
23
22
  #
24
- # Tags: AdGroupService.get
23
+ # Note: AdWords for Video API is a Beta feature.
24
+ #
25
+ # Tags: VideoCampaignCriterionService.get
25
26
 
26
27
  require 'adwords_api'
27
28
 
28
- def get_ad_groups(campaign_id)
29
+ def get_video_campaign_criteria(campaign_id)
29
30
  # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
30
31
  # when called without parameters.
31
32
  adwords = AdwordsApi::Api.new
@@ -34,15 +35,12 @@ def get_ad_groups(campaign_id)
34
35
  # the configuration file or provide your own logger:
35
36
  # adwords.logger = Logger.new('adwords_xml.log')
36
37
 
37
- ad_group_srv = adwords.service(:AdGroupService, API_VERSION)
38
+ vtgc_srv =
39
+ adwords.service(:VideoCampaignCriterionService, API_VERSION)
38
40
 
39
- # Get all the ad groups for this campaign.
41
+ # Get all criteria for the campaign.
40
42
  selector = {
41
- :fields => ['Id', 'Name'],
42
- :ordering => [{:field => 'Name', :sort_order => 'ASCENDING'}],
43
- :predicates => [
44
- {:field => 'CampaignId', :operator => 'IN', :values => [campaign_id]}
45
- ],
43
+ :campaign_ids => [campaign_id],
46
44
  :paging => {
47
45
  :start_index => 0,
48
46
  :number_results => PAGE_SIZE
@@ -53,11 +51,14 @@ def get_ad_groups(campaign_id)
53
51
  offset, page = 0, {}
54
52
 
55
53
  begin
56
- page = ad_group_srv.get(selector)
54
+ page = vtgc_srv.get(selector)
57
55
  if page[:entries]
58
- page[:entries].each do |ad_group|
59
- puts "Ad group name is '%s' and ID is %d" %
60
- [ad_group[:name], ad_group[:id]]
56
+ page[:entries].each do |criterion|
57
+ negative_str =
58
+ (criterion[:xsi_type] == 'NegativeVideoCampaignCriterion') ?
59
+ ' negative' : ''
60
+ puts "Video%s criterion ID %d or type '%s'" % [negative_str,
61
+ criterion[:criterion][:id], criterion[:criterion][:xsi_type]]
61
62
  end
62
63
  # Increment values to request the next page.
63
64
  offset += PAGE_SIZE
@@ -66,19 +67,19 @@ def get_ad_groups(campaign_id)
66
67
  end while page[:total_num_entries] > offset
67
68
 
68
69
  if page.include?(:total_num_entries)
69
- puts "\tCampaign ID %d has %d ad group(s)." %
70
- [campaign_id, page[:total_num_entries]]
70
+ puts "\tTotal number of criteria found: %d." % [page[:total_num_entries]]
71
71
  end
72
72
  end
73
73
 
74
74
  if __FILE__ == $0
75
- API_VERSION = :v201206
75
+ API_VERSION = :v201209
76
76
  PAGE_SIZE = 500
77
77
 
78
78
  begin
79
- # Campaign ID to get ad groups for.
79
+ # Campaign ID to get criteria for.
80
80
  campaign_id = 'INSERT_CAMPAIGN_ID_HERE'.to_i
81
- get_ad_groups(campaign_id)
81
+
82
+ get_video_campaign_criteria(campaign_id)
82
83
 
83
84
  # HTTP errors.
84
85
  rescue AdsCommon::Errors::HttpError => e