-
Notifications
You must be signed in to change notification settings - Fork 769
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ray Tsang
committed
Oct 10, 2014
1 parent
aded895
commit 4058cd3
Showing
270 changed files
with
229,109 additions
and
8,266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
### 5.5.2 | ||
|
||
AdWords: | ||
- Added v201409 support. | ||
|
||
### 5.5.1 | ||
|
||
AdWords: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<?php | ||
<?php | ||
/** | ||
* This example adds campaigns. | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<?php | ||
<?php | ||
/** | ||
* This example adds campaigns. | ||
* | ||
|
86 changes: 86 additions & 0 deletions
86
examples/AdWords/v201409/AccountManagement/CreateAccount.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
/** | ||
* This example creates a new account under an MCC account. Note: this example | ||
* must be run using the credentials of an MCC account, and by default the new | ||
* account will only be accessible via the parent MCC account. | ||
* | ||
* Tags: ManagedCustomerService.mutate | ||
* Restriction: adwords-only | ||
* | ||
* 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 GoogleApiAdsAdWords | ||
* @subpackage v201409 | ||
* @category WebServices | ||
* @copyright 2014, Google Inc. All Rights Reserved. | ||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, | ||
* Version 2.0 | ||
* @author Eric Koleda | ||
*/ | ||
|
||
// Include the initialization file | ||
require_once dirname(dirname(__FILE__)) . '/init.php'; | ||
|
||
/** | ||
* Runs the example. | ||
* @param AdWordsUser $user the user to run the example with | ||
*/ | ||
function CreateAccountExample(AdWordsUser $user) { | ||
// Get the service, which loads the required classes. | ||
$managedCustomerService = | ||
$user->GetService('ManagedCustomerService', ADWORDS_VERSION); | ||
|
||
// Create customer. | ||
$customer = new ManagedCustomer(); | ||
$customer->name = 'Account #' . uniqid(); | ||
$customer->currencyCode = 'EUR'; | ||
$customer->dateTimeZone = 'Europe/London'; | ||
|
||
// Create operation. | ||
$operation = new ManagedCustomerOperation(); | ||
$operation->operator = 'ADD'; | ||
$operation->operand = $customer; | ||
|
||
$operations = array($operation); | ||
|
||
// Make the mutate request. | ||
$result = $managedCustomerService->mutate($operations); | ||
|
||
// Display result. | ||
$customer = $result->value[0]; | ||
printf("Account with customer ID '%s' was created.\n", | ||
$customer->customerId); | ||
} | ||
|
||
// Don't run the example if the file is being included. | ||
if (__FILE__ != realpath($_SERVER['PHP_SELF'])) { | ||
return; | ||
} | ||
|
||
try { | ||
// Get AdWordsUser from credentials in "../auth.ini" | ||
// relative to the AdWordsUser.php file's directory. | ||
$user = new AdWordsUser(); | ||
|
||
// Log every SOAP XML request and response. | ||
$user->LogAll(); | ||
|
||
// Run the example. | ||
CreateAccountExample($user); | ||
} catch (Exception $e) { | ||
printf("An error has occurred: %s\n", $e->getMessage()); | ||
} |
148 changes: 148 additions & 0 deletions
148
examples/AdWords/v201409/AccountManagement/GetAccountChanges.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
<?php | ||
/** | ||
* This example gets the changes in the account during the last 24 hours. | ||
* Note: this example must be run using the credentials of an ad-serving | ||
* account. | ||
* | ||
* Tags: CustomerSyncService.get | ||
* | ||
* 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 GoogleApiAdsAdWords | ||
* @subpackage v201409 | ||
* @category WebServices | ||
* @copyright 2014, Google Inc. All Rights Reserved. | ||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, | ||
* Version 2.0 | ||
* @author Eric Koleda | ||
*/ | ||
|
||
// Include the initialization file | ||
require_once dirname(dirname(__FILE__)) . '/init.php'; | ||
|
||
/** | ||
* Runs the example. | ||
* @param AdWordsUser $user the user to run the example with | ||
*/ | ||
function GetAccountChangesExample(AdWordsUser $user) { | ||
// Get the service, which loads the required classes. | ||
$campaignService = $user->GetService('CampaignService', ADWORDS_VERSION); | ||
$customerSyncService = $user->GetService('CustomerSyncService', ADWORDS_VERSION); | ||
|
||
// Get an array of all campaign ids. | ||
$campaignIds = array(); | ||
$selector = new Selector(); | ||
$selector->fields = array('Id'); | ||
$selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE); | ||
do { | ||
$page = $campaignService->get($selector); | ||
if (isset($page->entries)) { | ||
foreach ($page->entries as $campaign) { | ||
$campaignIds[] = $campaign->id; | ||
} | ||
} | ||
$selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE; | ||
} while ($page->totalNumEntries > $selector->paging->startIndex); | ||
|
||
// Set the date time range, from 24 hours ago until now. | ||
$dateTimeRange = new DateTimeRange(); | ||
$dateTimeRange->min = date('Ymd his', strtotime('-1 day')); | ||
$dateTimeRange->max = date('Ymd his'); | ||
|
||
// Create selector. | ||
$selector = new CustomerSyncSelector(); | ||
$selector->dateTimeRange = $dateTimeRange; | ||
$selector->campaignIds = $campaignIds; | ||
|
||
// Make the get request. | ||
$accountChanges = $customerSyncService->get($selector); | ||
|
||
// Display results. | ||
if (isset($accountChanges)) { | ||
printf("Most recent change: %s\n", $accountChanges->lastChangeTimestamp); | ||
if (isset($accountChanges->changedCampaigns)) { | ||
foreach ($accountChanges->changedCampaigns as $campaignChangeData) { | ||
printf("Campaign with id '%.0f' has change status '%s'.\n", | ||
$campaignChangeData->campaignId, | ||
$campaignChangeData->campaignChangeStatus); | ||
if ($campaignChangeData->campaignChangeStatus != 'NEW') { | ||
printf("\tAdded ad extensions: %s\n", | ||
ArrayToString($campaignChangeData->addedAdExtensions)); | ||
printf("\tDeleted ad extensions: %s\n", | ||
ArrayToString($campaignChangeData->deletedAdExtensions)); | ||
printf("\tAdded campaign criteria: %s\n", | ||
ArrayToString($campaignChangeData->addedCampaignCriteria)); | ||
printf("\tDeleted campaign criteria: %s\n", | ||
ArrayToString($campaignChangeData->deletedCampaignCriteria)); | ||
printf("\tCampaign targeting changed: %s\n", | ||
$campaignChangeData->campaignTargetingChanged ? 'true' | ||
: 'false'); | ||
if (isset($campaignChangeData->changedAdGroups)) { | ||
foreach($campaignChangeData->changedAdGroups as | ||
$adGroupChangeData) { | ||
printf("\tAd Group with id '%.0f' has change status '%s'.\n", | ||
$adGroupChangeData->adGroupId, | ||
$adGroupChangeData->adGroupChangeStatus); | ||
if ($adGroupChangeData->adGroupChangeStatus != 'NEW') { | ||
printf("\t\tChanged ads: %s\n", | ||
ArrayToString($adGroupChangeData->changedAds)); | ||
printf("\t\tChanged criteria: %s\n", | ||
ArrayToString($adGroupChangeData->changedCriteria)); | ||
printf("\t\tDeleted criteria: %s\n", | ||
ArrayToString($adGroupChangeData->deletedCriteria)); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} else { | ||
print "No changes were found.\n"; | ||
} | ||
} | ||
|
||
/** | ||
* Converts an array of values to a comma-separated string. | ||
* @param array $array an array of values that can be converted to a string | ||
* @return string a comma-separated string of the values | ||
*/ | ||
function ArrayToString($array) { | ||
if (!isset($array)) { | ||
return ''; | ||
} else { | ||
return implode(', ', $array); | ||
} | ||
} | ||
|
||
// Don't run the example if the file is being included. | ||
if (__FILE__ != realpath($_SERVER['PHP_SELF'])) { | ||
return; | ||
} | ||
|
||
try { | ||
// Get AdWordsUser from credentials in "../auth.ini" | ||
// relative to the AdWordsUser.php file's directory. | ||
$user = new AdWordsUser(); | ||
|
||
// Log every SOAP XML request and response. | ||
$user->LogAll(); | ||
|
||
// Run the example. | ||
GetAccountChangesExample($user); | ||
} catch (Exception $e) { | ||
printf("An error has occurred: %s\n", $e->getMessage()); | ||
} |
125 changes: 125 additions & 0 deletions
125
examples/AdWords/v201409/AccountManagement/GetAccountHierarchy.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
<?php | ||
/** | ||
* This example gets the account hierarchy under the current account. Note: this | ||
* example must be run using the credentials of an MCC account. | ||
* | ||
* Tags: ManagedCustomerService.get | ||
* Restriction: adwords-only | ||
* | ||
* 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 GoogleApiAdsAdWords | ||
* @subpackage v201409 | ||
* @category WebServices | ||
* @copyright 2014, Google Inc. All Rights Reserved. | ||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, | ||
* Version 2.0 | ||
* @author Eric Koleda | ||
*/ | ||
|
||
// Include the initialization file | ||
require_once dirname(dirname(__FILE__)) . '/init.php'; | ||
|
||
/** | ||
* Runs the example. | ||
* @param AdWordsUser $user the user to run the example with | ||
*/ | ||
function GetAccountHierarchyExample(AdWordsUser $user) { | ||
// Get the service, which loads the required classes. | ||
$managedCustomerService = | ||
$user->GetService('ManagedCustomerService', ADWORDS_VERSION); | ||
|
||
// Create selector. | ||
$selector = new Selector(); | ||
// Specify the fields to retrieve. | ||
$selector->fields = array('CustomerId', 'Name'); | ||
|
||
// Make the get request. | ||
$graph = $managedCustomerService->get($selector); | ||
|
||
// Display serviced account graph. | ||
if (isset($graph->entries)) { | ||
// Create map from customerId to parent and child links. | ||
$childLinks = array(); | ||
$parentLinks = array(); | ||
if (isset($graph->links)) { | ||
foreach ($graph->links as $link) { | ||
$childLinks[$link->managerCustomerId][] = $link; | ||
$parentLinks[$link->clientCustomerId][] = $link; | ||
} | ||
} | ||
// Create map from customerID to account, and find root account. | ||
$accounts = array(); | ||
$rootAccount = NULL; | ||
foreach ($graph->entries as $account) { | ||
$accounts[$account->customerId] = $account; | ||
if (!array_key_exists($account->customerId, $parentLinks)) { | ||
$rootAccount = $account; | ||
} | ||
} | ||
// The root account may not be returned in the sandbox. | ||
if (!isset($rootAccount)) { | ||
$rootAccount = new Account(); | ||
$rootAccount->customerId = 0; | ||
} | ||
// Display account tree. | ||
print "(Customer Id, Account Name)\n"; | ||
DisplayAccountTree($rootAccount, NULL, $accounts, $childLinks, 0); | ||
} else { | ||
print "No serviced accounts were found.\n"; | ||
} | ||
} | ||
|
||
/** | ||
* Displays an account tree, starting at the account and link provided, and | ||
* recursing to all child accounts. | ||
* @param Account $account the account to display | ||
* @param Link $link the link used to reach this account | ||
* @param array $accounts a map from customerId to account | ||
* @param array $links a map from customerId to child links | ||
* @param int $depth the depth of the current account in the tree | ||
*/ | ||
function DisplayAccountTree($account, $link, $accounts, $links, $depth) { | ||
print str_repeat('-', $depth * 2); | ||
printf("%s, %s\n", $account->customerId, $account->name); | ||
if (array_key_exists($account->customerId, $links)) { | ||
foreach ($links[$account->customerId] as $childLink) { | ||
$childAccount = $accounts[$childLink->clientCustomerId]; | ||
DisplayAccountTree($childAccount, $childLink, $accounts, $links, | ||
$depth +1); | ||
} | ||
} | ||
} | ||
|
||
// Don't run the example if the file is being included. | ||
if (__FILE__ != realpath($_SERVER['PHP_SELF'])) { | ||
return; | ||
} | ||
|
||
try { | ||
// Get AdWordsUser from credentials in "../auth.ini" | ||
// relative to the AdWordsUser.php file's directory. | ||
$user = new AdWordsUser(); | ||
|
||
// Log every SOAP XML request and response. | ||
$user->LogAll(); | ||
|
||
// Run the example. | ||
GetAccountHierarchyExample($user); | ||
} catch (Exception $e) { | ||
printf("An error has occurred: %s\n", $e->getMessage()); | ||
} |
Oops, something went wrong.