-
Notifications
You must be signed in to change notification settings - Fork 770
/
UpdateCreatives.php
executable file
·93 lines (81 loc) · 3.08 KB
/
UpdateCreatives.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/**
* This example updates a creative's destination URL. To determine which
* creatives exist, run GetAllCreatives.php.
*
* Tags: CreativeService.getCreativesByStatement
* Tags: CreativeService.updateCreatives
*
* PHP version 5
*
* Copyright 2014, 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 GoogleApiAdsDfp
* @subpackage v201411
* @category WebServices
* @copyright 2014, Google Inc. All Rights Reserved.
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License,
* Version 2.0
* @author Vincent Tsao
*/
error_reporting(E_STRICT | E_ALL);
// You can set the include path to src directory or reference
// DfpUser.php directly via require_once.
// $path = '/path/to/dfp_api_php_lib/src';
$path = dirname(__FILE__) . '/../../../../src';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
require_once 'Google/Api/Ads/Dfp/Lib/DfpUser.php';
require_once 'Google/Api/Ads/Dfp/Util/StatementBuilder.php';
require_once dirname(__FILE__) . '/../../../Common/ExampleUtils.php';
// Set the ID of the creative to update.
$creativeId = 'INSERT_CREATIVE_ID_HERE';
try {
// Get DfpUser from credentials in "../auth.ini"
// relative to the DfpUser.php file's directory.
$user = new DfpUser();
// Log SOAP XML request and response.
$user->LogDefaults();
// Get the CreativeService.
$creativeService = $user->GetService('CreativeService', 'v201411');
// Create a statement to select a single creative by ID.
$statementBuilder = new StatementBuilder();
$statementBuilder->Where('id = :id')
->OrderBy('id ASC')
->Limit(1)
->WithBindVariableValue('id', $creativeId);
// Get the creative.
$page = $creativeService->getCreativesByStatement(
$statementBuilder->ToStatement());
$creative = $page->results[0];
// Only update the destination URL if it has one.
if ($creative instanceof HasDestinationUrlCreative) {
// Update the destination URL of the creative.
$creative->destinationUrl = 'https://news.google.com';
// Update the creative on the server.
$creatives = $creativeService->updateCreatives(array($creative));
foreach ($creatives as $updatedCreative) {
printf("Creative with ID %d, and name '%s' was updated.\n",
$updatedCreative->id, $updatedCreative->name);
}
} else {
printf("No creatives were updated.\n");
}
} catch (OAuth2Exception $e) {
ExampleUtils::CheckForOAuth2Errors($e);
} catch (ValidationException $e) {
ExampleUtils::CheckForOAuth2Errors($e);
} catch (Exception $e) {
printf("%s\n", $e->getMessage());
}