PageRenderTime 38ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/php/examples/v1_17/CreateImageAsset.php

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