PageRenderTime 33ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/php/examples/v1_17/CreatePlacement.php

http://google-api-dfa-examples.googlecode.com/
PHP | 118 lines | 58 code | 11 blank | 49 comment | 0 complexity | d066631f37ff0f7cde092fe4ca3f368f MD5 | raw file
  1. <?php
  2. /**
  3. * This example creates a placement in a given campaign. Requires the DFA site
  4. * ID and campaign ID in which the placement will be created into. To create a
  5. * campaign, run CreateCampaign.php. To get a size ID, run GetSize.php. To get
  6. * placement types, run GetPlacementTypes.php.
  7. *
  8. * Tags: placement.savePlacement
  9. *
  10. * PHP version 5
  11. * PHP extensions: SoapClient.
  12. *
  13. * Copyright 2012, Google Inc. All Rights Reserved.
  14. *
  15. * Licensed under the Apache License, Version 2.0 (the "License");
  16. * you may not use this file except in compliance with the License.
  17. * You may obtain a copy of the License at
  18. *
  19. * http://www.apache.org/licenses/LICENSE-2.0
  20. *
  21. * Unless required by applicable law or agreed to in writing, software
  22. * distributed under the License is distributed on an "AS IS" BASIS,
  23. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  24. * See the License for the specific language governing permissions and
  25. * limitations under the License.
  26. *
  27. * @package GoogleApiAdsDfa
  28. * @subpackage v1_17
  29. * @category WebServices
  30. * @copyright 2012, Google Inc. All Rights Reserved.
  31. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License,
  32. * Version 2.0
  33. * @author Joseph DiLallo <api.jdilallo@gmail.com>
  34. */
  35. require_once 'DfaHeadersUtil.php';
  36. // Provide information on placement to be created.
  37. $dfaSiteId = (float) 'INSERT_DFA_SITE_ID_HERE';
  38. $campaignId = (float) 'INSERT_CAMPAIGN_ID_HERE';
  39. $pricingType = (int) 'INSERT_PRICING_TYPE_ID_HERE';
  40. $placementType = (int) 'INSERT_PLACEMENT_TYPE_ID_HERE';
  41. $sizeId = (float) 'INSERT_SIZE_ID_HERE';
  42. // Provide information required for DFA headers.
  43. $username = 'INSERT_USERNAME_HERE';
  44. $authToken = 'INSERT_AUTHENTICATION_TOKEN_HERE';
  45. $applicationName = 'INSERT_APPLICATION_NAME_HERE';
  46. // Set SOAP and XML settings. To send requests to the production environment,
  47. // replace "advertisersapitest.doubleclick.net" with
  48. // "advertisersapi.doubleclick.net" in the wsdl URL. The namespace will always
  49. // be "www.doubleclick.net", even in the test environment.
  50. $placementWsdl = 'https://advertisersapitest.doubleclick.net/v1.17/api/' .
  51. 'dfa-api/placement?wsdl';
  52. $namespace = 'http://www.doubleclick.net/dfa-api/v1.17';
  53. $options = array('encoding' => 'utf-8');
  54. // Get PlacementService.
  55. $placementService = new SoapClient($placementWsdl, $options);
  56. // Set headers.
  57. $headers = array(DfaHeadersUtil::createWsseHeader($username, $authToken),
  58. DfaHeadersUtil::createRequestHeader($namespace, $applicationName));
  59. $placementService->__setSoapHeaders($headers);
  60. // Create placement structure.
  61. $placement = array(
  62. 'id' => 0,
  63. 'name' => 'Placement ' . uniqid(),
  64. 'campaignId' => $campaignId,
  65. 'placementType' => $placementType,
  66. 'dfaSiteId' => $dfaSiteId,
  67. 'sizeId' => $sizeId,
  68. 'pricingSchedule' => array(
  69. 'startDate' => strtotime('now'),
  70. 'endDate' => strtotime('+1 month'),
  71. 'pricingType' => $pricingType,
  72. 'capCostOption' => 0,
  73. 'flighted' => FALSE),
  74. 'archived' => FALSE,
  75. 'contentCategoryId' => 0,
  76. 'placementGroupId' => 0,
  77. 'placementStrategyId' => 0,
  78. 'siteId' => 0);
  79. // Set the placement tag settings by retrieving all of the regular placement tag
  80. // options and using them.
  81. try {
  82. // Fetch the tag options.
  83. $placementTagOptions = $placementService->getRegularPlacementTagOptions();
  84. } catch (Exception $e) {
  85. print $e->getMessage();
  86. exit(1);
  87. }
  88. // Place the tag options in a tag settings configuration and add it to the
  89. // placement.
  90. $tagSettings = array(
  91. 'includeClickTrackingStringInTags' => FALSE,
  92. 'keywordHandlingOption' => 0);
  93. $tagTypes = array();
  94. foreach($placementTagOptions as $tag) {
  95. $tagTypes[] = $tag->id;
  96. }
  97. $tagSettings['tagTypes'] = $tagTypes;
  98. $placement['tagSettings'] = $tagSettings;
  99. try {
  100. // Save the placement.
  101. $result = $placementService->savePlacement($placement);
  102. } catch (Exception $e) {
  103. print $e->getMessage();
  104. exit(1);
  105. }
  106. // Display the ID of the newly created placement.
  107. print "Placement with ID \"" . $result->id . "\" was created.";