PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/php/examples/v1_16/CreateContentCategory.php

http://google-api-dfa-examples.googlecode.com/
PHP | 72 lines | 24 code | 8 blank | 40 comment | 0 complexity | 85e0d8f57ccee0f24cacd0befa05916e MD5 | raw file
  1. <?php
  2. /**
  3. * This example creates a content category.
  4. *
  5. * Tags: contentcategory.saveContentCategory
  6. *
  7. * PHP version 5
  8. * PHP extensions: SoapClient.
  9. *
  10. * Copyright 2011, Google Inc. All Rights Reserved.
  11. *
  12. * Licensed under the Apache License, Version 2.0 (the "License");
  13. * you may not use this file except in compliance with the License.
  14. * You may obtain a copy of the License at
  15. *
  16. * http://www.apache.org/licenses/LICENSE-2.0
  17. *
  18. * Unless required by applicable law or agreed to in writing, software
  19. * distributed under the License is distributed on an "AS IS" BASIS,
  20. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  21. * See the License for the specific language governing permissions and
  22. * limitations under the License.
  23. *
  24. * @package GoogleApiAdsDfa
  25. * @subpackage v1_16
  26. * @category WebServices
  27. * @copyright 2011, Google Inc. All Rights Reserved.
  28. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License,
  29. * Version 2.0
  30. * @author Joseph DiLallo <api.jdilallo@gmail.com>
  31. */
  32. require_once 'DfaHeadersUtil.php';
  33. // Provide information required for DFA headers.
  34. $username = 'INSERT_USERNAME_HERE';
  35. $authToken = 'INSERT_AUTHENTICATION_TOKEN_HERE';
  36. $applicationName = 'INSERT_APPLICATION_NAME_HERE';
  37. // Set SOAP and XML settings. To send requests to the production environment,
  38. // replace "advertisersapitest.doubleclick.net" with
  39. // "advertisersapi.doubleclick.net" in the wsdl URL. The namespace will always
  40. // be "www.doubleclick.net", even in the test environment.
  41. $contentCategoryWsdl = 'https://advertisersapitest.doubleclick.net/v1.16/api/' .
  42. 'dfa-api/contentcategory?wsdl';
  43. $namespace = 'http://www.doubleclick.net/dfa-api/v1.16';
  44. $options = array('encoding' => 'utf-8');
  45. // Get ContentCategoryService.
  46. $contentCategoryService = new SoapClient($contentCategoryWsdl, $options);
  47. // Set headers.
  48. $headers = array(DfaHeadersUtil::createWsseHeader($username, $authToken),
  49. DfaHeadersUtil::createRequestHeader($namespace, $applicationName));
  50. $contentCategoryService->__setSoapHeaders($headers);
  51. // Create content category structure.
  52. $contentCategory = array(
  53. 'id' => 0,
  54. 'name' => 'Content Category ' . uniqid(),
  55. 'description' => 'Created from the API.');
  56. try {
  57. // Save the content category.
  58. $result = $contentCategoryService->saveContentCategory($contentCategory);
  59. } catch (Exception $e) {
  60. print $e->getMessage();
  61. exit(1);
  62. }
  63. // Display the ID of the newly created content category.
  64. print "Content category with ID \"" . $result->id . "\" was created.";