/php/examples/v1_17/CreateImageAsset.php
PHP | 79 lines | 28 code | 9 blank | 42 comment | 0 complexity | f00c4a9238d4654a53b93c8a38a60332 MD5 | raw file
- <?php
- /**
- * This example creates an image creative asset associated with a given
- * advertiser. To create an advertiser, run CreateAdvertiser.php.
- *
- * Tags: creative.saveCreativeAsset
- *
- * PHP version 5
- * PHP extensions: SoapClient.
- *
- * Copyright 2012, Google Inc. All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * @package GoogleApiAdsDfa
- * @subpackage v1_17
- * @category WebServices
- * @copyright 2012, Google Inc. All Rights Reserved.
- * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License,
- * Version 2.0
- * @author Joseph DiLallo <api.jdilallo@gmail.com>
- */
- require_once 'DfaHeadersUtil.php';
- // Provide information on the creative asset to be created.
- $advertiserId = (float) 'INSERT_ADVERTISER_ID_HERE';
- // Provide information required for DFA headers.
- $username = 'INSERT_USERNAME_HERE';
- $authToken = 'INSERT_AUTHENTICATION_TOKEN_HERE';
- $applicationName = 'INSERT_APPLICATION_NAME_HERE';
- // Set SOAP and XML settings. To send requests to the production environment,
- // replace "advertisersapitest.doubleclick.net" with
- // "advertisersapi.doubleclick.net" in the wsdl URL. The namespace will always
- // be "www.doubleclick.net", even in the test environment.
- $creativeWsdl = 'https://advertisersapitest.doubleclick.net/v1.17/api/' .
- 'dfa-api/creative?wsdl';
- $namespace = 'http://www.doubleclick.net/dfa-api/v1.17';
- $options = array('encoding' => 'utf-8');
- // Get CreativeService.
- $creativeService = new SoapClient($creativeWsdl, $options);
- // Set headers.
- $headers = array(DfaHeadersUtil::createWsseHeader($username, $authToken),
- DfaHeadersUtil::createRequestHeader($namespace, $applicationName));
- $creativeService->__setSoapHeaders($headers);
- // Create creative asset structure.
- $creativeAsset = array(
- 'name' => 'Asset ' . uniqid(),
- 'advertiserId' => $advertiserId,
- 'content' => file_get_contents(
- 'http://code.google.com/images/code_logo.gif'),
- 'forHTMLCreatives' => FALSE);
- try {
- // Save the creative asset.
- $result = $creativeService->saveCreativeAsset($creativeAsset);
- } catch (Exception $e) {
- print $e->getMessage();
- exit(1);
- }
- // Display the filename of the newly created creative asset.
- print "Creative asset with filename of \"" . $result->savedFilename
- . "\" was created.";