Skip to content

Commit 7161de6

Browse files
committed
Preparing src for release 13.1.0
1 parent d953608 commit 7161de6

File tree

180 files changed

+253633
-1217
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

180 files changed

+253633
-1217
lines changed

ChangeLog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
### 13.1.0
2+
3+
AdWords:
4+
- Added support and examples for v201609.
5+
- Fixed [issue #156](https://github.com/googleads/googleads-php-lib/issues/156).
6+
- Fixed [issue #164](https://github.com/googleads/googleads-php-lib/pull/164).
7+
18
### 13.0.0
29

310
Common:
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
/**
3+
* This example creates a new account under an AdWords manager account. Note:
4+
* this example must be run using the credentials of an AdWords manager account,
5+
* and by default the new account will only be accessible via the parent AdWords
6+
* manager account.
7+
*
8+
* PHP version 5
9+
*
10+
* Copyright 2016, 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 GoogleApiAdsAdWords
25+
* @subpackage v201609
26+
* @category WebServices
27+
* @copyright 2016, Google Inc. All Rights Reserved.
28+
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License,
29+
* Version 2.0
30+
*/
31+
32+
// Include the initialization file
33+
require_once dirname(dirname(__FILE__)) . '/init.php';
34+
35+
/**
36+
* Runs the example.
37+
* @param AdWordsUser $user the user to run the example with
38+
*/
39+
function CreateAccountExample(AdWordsUser $user) {
40+
// Get the service, which loads the required classes.
41+
$managedCustomerService =
42+
$user->GetService('ManagedCustomerService', ADWORDS_VERSION);
43+
44+
// Create customer.
45+
$customer = new ManagedCustomer();
46+
$customer->name = 'Account #' . uniqid();
47+
$customer->currencyCode = 'EUR';
48+
$customer->dateTimeZone = 'Europe/London';
49+
50+
// Create operation.
51+
$operation = new ManagedCustomerOperation();
52+
$operation->operator = 'ADD';
53+
$operation->operand = $customer;
54+
55+
$operations = array($operation);
56+
57+
// Make the mutate request.
58+
$result = $managedCustomerService->mutate($operations);
59+
60+
// Display result.
61+
$customer = $result->value[0];
62+
printf("Account with customer ID '%s' was created.\n",
63+
$customer->customerId);
64+
}
65+
66+
// Don't run the example if the file is being included.
67+
if (__FILE__ != realpath($_SERVER['PHP_SELF'])) {
68+
return;
69+
}
70+
71+
try {
72+
// Get AdWordsUser from credentials in "../auth.ini"
73+
// relative to the AdWordsUser.php file's directory.
74+
$user = new AdWordsUser();
75+
76+
// Log every SOAP XML request and response.
77+
$user->LogAll();
78+
79+
// Run the example.
80+
CreateAccountExample($user);
81+
} catch (Exception $e) {
82+
printf("An error has occurred: %s\n", $e->getMessage());
83+
}
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<?php
2+
/**
3+
* This example gets the changes in the account during the last 24 hours.
4+
* Note: this example must be run using the credentials of an ad-serving
5+
* account.
6+
*
7+
* PHP version 5
8+
*
9+
* Copyright 2016, Google Inc. All Rights Reserved.
10+
*
11+
* Licensed under the Apache License, Version 2.0 (the "License");
12+
* you may not use this file except in compliance with the License.
13+
* You may obtain a copy of the License at
14+
*
15+
* http://www.apache.org/licenses/LICENSE-2.0
16+
*
17+
* Unless required by applicable law or agreed to in writing, software
18+
* distributed under the License is distributed on an "AS IS" BASIS,
19+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20+
* See the License for the specific language governing permissions and
21+
* limitations under the License.
22+
*
23+
* @package GoogleApiAdsAdWords
24+
* @subpackage v201609
25+
* @category WebServices
26+
* @copyright 2016, Google Inc. All Rights Reserved.
27+
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License,
28+
* Version 2.0
29+
*/
30+
31+
// Include the initialization file
32+
require_once dirname(dirname(__FILE__)) . '/init.php';
33+
34+
/**
35+
* Runs the example.
36+
* @param AdWordsUser $user the user to run the example with
37+
*/
38+
function GetAccountChangesExample(AdWordsUser $user) {
39+
// Get the service, which loads the required classes.
40+
$campaignService = $user->GetService('CampaignService', ADWORDS_VERSION);
41+
$customerSyncService = $user->GetService('CustomerSyncService', ADWORDS_VERSION);
42+
43+
// Get an array of all campaign ids.
44+
$campaignIds = array();
45+
$selector = new Selector();
46+
$selector->fields = array('Id');
47+
$selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);
48+
do {
49+
$page = $campaignService->get($selector);
50+
if (isset($page->entries)) {
51+
foreach ($page->entries as $campaign) {
52+
$campaignIds[] = $campaign->id;
53+
}
54+
}
55+
$selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE;
56+
} while ($page->totalNumEntries > $selector->paging->startIndex);
57+
58+
// Set the date time range, from 24 hours ago until now.
59+
$dateTimeRange = new DateTimeRange();
60+
$dateTimeRange->min = date('Ymd his', strtotime('-1 day'));
61+
$dateTimeRange->max = date('Ymd his');
62+
63+
// Create selector.
64+
$selector = new CustomerSyncSelector();
65+
$selector->dateTimeRange = $dateTimeRange;
66+
$selector->campaignIds = $campaignIds;
67+
68+
// Make the get request.
69+
$accountChanges = $customerSyncService->get($selector);
70+
71+
// Display results.
72+
if (isset($accountChanges)) {
73+
printf("Most recent change: %s\n", $accountChanges->lastChangeTimestamp);
74+
if (isset($accountChanges->changedCampaigns)) {
75+
foreach ($accountChanges->changedCampaigns as $campaignChangeData) {
76+
printf("Campaign with id '%.0f' has change status '%s'.\n",
77+
$campaignChangeData->campaignId,
78+
$campaignChangeData->campaignChangeStatus);
79+
if ($campaignChangeData->campaignChangeStatus != 'NEW') {
80+
printf("\tAdded campaign criteria: %s\n",
81+
ArrayToString($campaignChangeData->addedCampaignCriteria));
82+
printf("\tRemoved campaign criteria: %s\n",
83+
ArrayToString($campaignChangeData->removedCampaignCriteria));
84+
if (isset($campaignChangeData->changedAdGroups)) {
85+
foreach($campaignChangeData->changedAdGroups as
86+
$adGroupChangeData) {
87+
printf("\tAd Group with id '%.0f' has change status '%s'.\n",
88+
$adGroupChangeData->adGroupId,
89+
$adGroupChangeData->adGroupChangeStatus);
90+
if ($adGroupChangeData->adGroupChangeStatus != 'NEW') {
91+
printf("\t\tChanged ads: %s\n",
92+
ArrayToString($adGroupChangeData->changedAds));
93+
printf("\t\tChanged criteria: %s\n",
94+
ArrayToString($adGroupChangeData->changedCriteria));
95+
printf("\t\tRemoved criteria: %s\n",
96+
ArrayToString($adGroupChangeData->removedCriteria));
97+
}
98+
}
99+
}
100+
}
101+
}
102+
}
103+
} else {
104+
print "No changes were found.\n";
105+
}
106+
}
107+
108+
/**
109+
* Converts an array of values to a comma-separated string.
110+
* @param array $array an array of values that can be converted to a string
111+
* @return string a comma-separated string of the values
112+
*/
113+
function ArrayToString($array) {
114+
if (!isset($array)) {
115+
return '';
116+
} else {
117+
return implode(', ', $array);
118+
}
119+
}
120+
121+
// Don't run the example if the file is being included.
122+
if (__FILE__ != realpath($_SERVER['PHP_SELF'])) {
123+
return;
124+
}
125+
126+
try {
127+
// Get AdWordsUser from credentials in "../auth.ini"
128+
// relative to the AdWordsUser.php file's directory.
129+
$user = new AdWordsUser();
130+
131+
// Log every SOAP XML request and response.
132+
$user->LogAll();
133+
134+
// Run the example.
135+
GetAccountChangesExample($user);
136+
} catch (Exception $e) {
137+
printf("An error has occurred: %s\n", $e->getMessage());
138+
}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
<?php
2+
/**
3+
* This example gets the account hierarchy under the current account. Note: this
4+
* example must be run using the credentials of an AdWords manager account.
5+
*
6+
* PHP version 5
7+
*
8+
* Copyright 2016, Google Inc. All Rights Reserved.
9+
*
10+
* Licensed under the Apache License, Version 2.0 (the "License");
11+
* you may not use this file except in compliance with the License.
12+
* You may obtain a copy of the License at
13+
*
14+
* http://www.apache.org/licenses/LICENSE-2.0
15+
*
16+
* Unless required by applicable law or agreed to in writing, software
17+
* distributed under the License is distributed on an "AS IS" BASIS,
18+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
* See the License for the specific language governing permissions and
20+
* limitations under the License.
21+
*
22+
* @package GoogleApiAdsAdWords
23+
* @subpackage v201609
24+
* @category WebServices
25+
* @copyright 2016, Google Inc. All Rights Reserved.
26+
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License,
27+
* Version 2.0
28+
*/
29+
30+
// Include the initialization file
31+
require_once dirname(dirname(__FILE__)) . '/init.php';
32+
33+
/**
34+
* Runs the example.
35+
* @param AdWordsUser $user the user to run the example with
36+
*/
37+
function GetAccountHierarchyExample(AdWordsUser $user) {
38+
// Get the service, which loads the required classes.
39+
$managedCustomerService =
40+
$user->GetService('ManagedCustomerService', ADWORDS_VERSION);
41+
42+
// Create selector.
43+
$selector = new Selector();
44+
// Specify the fields to retrieve.
45+
$selector->fields = array('CustomerId', 'Name');
46+
$selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);
47+
48+
// Create map from customerID to account.
49+
$accounts = array();
50+
// Create map from customerId to parent and child links.
51+
$childLinks = array();
52+
$parentLinks = array();
53+
do {
54+
// Make the get request.
55+
$graph = $managedCustomerService->get($selector);
56+
57+
// Create links between manager and clients.
58+
if (isset($graph->entries)) {
59+
if (isset($graph->links)) {
60+
foreach ($graph->links as $link) {
61+
$childLinks[$link->managerCustomerId][] = $link;
62+
$parentLinks[$link->clientCustomerId] = $link;
63+
}
64+
}
65+
foreach ($graph->entries as $account) {
66+
$accounts[$account->customerId] = $account;
67+
}
68+
}
69+
$selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE;
70+
} while ($selector->paging->startIndex < $graph->totalNumEntries);
71+
72+
$rootAccount = null;
73+
foreach ($accounts as $account) {
74+
if (!array_key_exists($account->customerId, $parentLinks)) {
75+
$rootAccount = $account;
76+
break;
77+
}
78+
}
79+
80+
if ($rootAccount !== null) {
81+
// Display account tree.
82+
print "(Customer Id, Account Name)\n";
83+
DisplayAccountTree($rootAccount, $accounts, $childLinks, 0);
84+
} else {
85+
printf("No accounts were found.\n");
86+
}
87+
}
88+
89+
/**
90+
* Displays an account tree, starting at the account provided, and recursing to
91+
* all child accounts.
92+
* @param ManagedCustomer $account the account to display
93+
* @param array $accounts a map from customerId to account
94+
* @param array $links a map from customerId to child links
95+
* @param int $depth the depth of the current account in the tree
96+
*/
97+
function DisplayAccountTree($account, $accounts, $links, $depth) {
98+
print str_repeat('-', $depth * 2);
99+
printf("%s, %s\n", $account->customerId, $account->name);
100+
if (array_key_exists($account->customerId, $links)) {
101+
foreach ($links[$account->customerId] as $childLink) {
102+
$childAccount = $accounts[$childLink->clientCustomerId];
103+
DisplayAccountTree($childAccount, $accounts, $links, $depth + 1);
104+
}
105+
}
106+
}
107+
108+
// Don't run the example if the file is being included.
109+
if (__FILE__ != realpath($_SERVER['PHP_SELF'])) {
110+
return;
111+
}
112+
113+
try {
114+
// Get AdWordsUser from credentials in "../auth.ini"
115+
// relative to the AdWordsUser.php file's directory.
116+
$user = new AdWordsUser();
117+
118+
// Log every SOAP XML request and response.
119+
$user->LogAll();
120+
121+
// Run the example.
122+
GetAccountHierarchyExample($user);
123+
} catch (Exception $e) {
124+
printf("An error has occurred: %s\n", $e->getMessage());
125+
}

0 commit comments

Comments
 (0)