-
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
1 parent
eeacf8a
commit 3a2249a
Showing
1,346 changed files
with
348,192 additions
and
1,473 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,9 @@ | ||
### 35.2.0 | ||
|
||
##### AdWords | ||
|
||
* Added support and examples for v201806. | ||
|
||
### 35.1.0 | ||
|
||
##### DFP | ||
|
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
91 changes: 91 additions & 0 deletions
91
examples/AdWords/v201806/AccountManagement/AcceptServiceLink.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,91 @@ | ||
<?php | ||
/** | ||
* Copyright 2017 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. | ||
*/ | ||
|
||
namespace Google\AdsApi\Examples\AdWords\v201806\AccountManagement; | ||
|
||
require __DIR__ . '/../../../../vendor/autoload.php'; | ||
|
||
use Google\AdsApi\AdWords\AdWordsServices; | ||
use Google\AdsApi\AdWords\AdWordsSession; | ||
use Google\AdsApi\AdWords\AdWordsSessionBuilder; | ||
use Google\AdsApi\AdWords\v201806\cm\Operator; | ||
use Google\AdsApi\AdWords\v201806\mcm\CustomerService; | ||
use Google\AdsApi\AdWords\v201806\mcm\ServiceLink; | ||
use Google\AdsApi\AdWords\v201806\mcm\ServiceLinkLinkStatus; | ||
use Google\AdsApi\AdWords\v201806\mcm\ServiceLinkOperation; | ||
use Google\AdsApi\AdWords\v201806\mcm\ServiceType; | ||
use Google\AdsApi\Common\OAuth2TokenBuilder; | ||
|
||
/** | ||
* This example accepts a pending invitation to link your AdWords account to a | ||
* Google Merchant Center account. | ||
*/ | ||
class AcceptServiceLink | ||
{ | ||
|
||
const SERVICE_LINK_ID = 'INSERT_SERVICE_LINK_ID_HERE'; | ||
|
||
public static function runExample( | ||
AdWordsServices $adWordsServices, | ||
AdWordsSession $session, | ||
$serviceLinkId | ||
) { | ||
$customerService = $adWordsServices->get($session, CustomerService::class); | ||
|
||
// Create service link. | ||
$serviceLink = new ServiceLink(); | ||
$serviceLink->setServiceLinkId($serviceLinkId); | ||
$serviceLink->setServiceType(ServiceType::MERCHANT_CENTER); | ||
$serviceLink->setLinkStatus(ServiceLinkLinkStatus::ACTIVE); | ||
|
||
// Create a service link operation and add it to the list. | ||
$operations = []; | ||
$operation = new ServiceLinkOperation(); | ||
$operation->setOperator(Operator::SET); | ||
$operation->setOperand($serviceLink); | ||
$operations[] = $operation; | ||
|
||
// Accept service links on the server and print out some information about | ||
// accepted service links. | ||
$serviceLinks = $customerService->mutateServiceLinks($operations); | ||
foreach ($serviceLinks as $serviceLink) { | ||
printf( | ||
"Service link with service link ID %d and type '%s' updated to status: %s.\n", | ||
$serviceLink->getServiceLinkId(), | ||
$serviceLink->getServiceType(), | ||
$serviceLink->getLinkStatus() | ||
); | ||
} | ||
} | ||
|
||
public static function main() | ||
{ | ||
// Generate a refreshable OAuth2 credential for authentication. | ||
$oAuth2Credential = (new OAuth2TokenBuilder())->fromFile()->build(); | ||
|
||
// Construct an API session configured from a properties file and the | ||
// OAuth2 credentials above. | ||
$session = (new AdWordsSessionBuilder())->fromFile()->withOAuth2Credential($oAuth2Credential)->build(); | ||
self::runExample( | ||
new AdWordsServices(), | ||
$session, | ||
intval(self::SERVICE_LINK_ID) | ||
); | ||
} | ||
} | ||
|
||
AcceptServiceLink::main(); |
90 changes: 90 additions & 0 deletions
90
examples/AdWords/v201806/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,90 @@ | ||
<?php | ||
/** | ||
* Copyright 2017 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. | ||
*/ | ||
|
||
namespace Google\AdsApi\Examples\AdWords\v201806\AccountManagement; | ||
|
||
require __DIR__ . '/../../../../vendor/autoload.php'; | ||
|
||
use Google\AdsApi\AdWords\AdWordsServices; | ||
use Google\AdsApi\AdWords\AdWordsSession; | ||
use Google\AdsApi\AdWords\AdWordsSessionBuilder; | ||
use Google\AdsApi\AdWords\v201806\cm\Operator; | ||
use Google\AdsApi\AdWords\v201806\mcm\ManagedCustomer; | ||
use Google\AdsApi\AdWords\v201806\mcm\ManagedCustomerOperation; | ||
use Google\AdsApi\AdWords\v201806\mcm\ManagedCustomerService; | ||
use Google\AdsApi\Common\OAuth2TokenBuilder; | ||
|
||
/** | ||
* This example creates a new account under an AdWords manager account. Note: | ||
* this example must be run using the credentials of an AdWords manager account, | ||
* and by default the new account will only be accessible via the parent AdWords | ||
* manager account. | ||
*/ | ||
class CreateAccount | ||
{ | ||
|
||
public static function runExample( | ||
AdWordsServices $adWordsServices, | ||
AdWordsSession $session | ||
) { | ||
$managedCustomerService = $adWordsServices->get( | ||
$session, | ||
ManagedCustomerService::class | ||
); | ||
|
||
// Create a managed customer. | ||
$customer = new ManagedCustomer(); | ||
$customer->setName('Account #' . uniqid()); | ||
$customer->setCurrencyCode('EUR'); | ||
$customer->setDateTimeZone('Europe/London'); | ||
|
||
// Create a managed customer operation and add it to the list. | ||
$operations = []; | ||
$operation = new ManagedCustomerOperation(); | ||
$operation->setOperator(Operator::ADD); | ||
$operation->setOperand($customer); | ||
// For whitelisted users only, uncomment two below commands to invite a | ||
// user to have access to an account on an ADD. An email will be sent to | ||
// that user inviting them to have access to the newly created account. | ||
// $operation->setInviteeEmail('invited_user1@example.com'); | ||
// $operation->setInviteeRole('ADMINISTRATIVE'); | ||
|
||
$operations[] = $operation; | ||
// Create a managed customer on the server and print out some info | ||
// about it. | ||
$customer = $managedCustomerService->mutate($operations)->getValue()[0]; | ||
printf( | ||
"Account with customer ID %d was created.\n", | ||
$customer->getCustomerId() | ||
); | ||
} | ||
|
||
public static function main() | ||
{ | ||
// Generate a refreshable OAuth2 credential for authentication. | ||
$oAuth2Credential = (new OAuth2TokenBuilder())->fromFile()->build(); | ||
|
||
// Construct an API session configured from a properties file and the | ||
// OAuth2 credentials above. | ||
// You can use withClientCustomerId() of AdWordsSessionBuilder to specify | ||
// your manager account ID under which you want to create an account. | ||
$session = (new AdWordsSessionBuilder())->fromFile()->withOAuth2Credential($oAuth2Credential)->build(); | ||
self::runExample(new AdWordsServices(), $session); | ||
} | ||
} | ||
|
||
CreateAccount::main(); |
165 changes: 165 additions & 0 deletions
165
examples/AdWords/v201806/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,165 @@ | ||
<?php | ||
/** | ||
* Copyright 2017 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. | ||
*/ | ||
|
||
namespace Google\AdsApi\Examples\AdWords\v201806\AccountManagement; | ||
|
||
require __DIR__ . '/../../../../vendor/autoload.php'; | ||
|
||
use Google\AdsApi\AdWords\AdWordsServices; | ||
use Google\AdsApi\AdWords\AdWordsSession; | ||
use Google\AdsApi\AdWords\AdWordsSessionBuilder; | ||
use Google\AdsApi\AdWords\v201806\ch\ChangeStatus; | ||
use Google\AdsApi\AdWords\v201806\ch\CustomerSyncSelector; | ||
use Google\AdsApi\AdWords\v201806\ch\CustomerSyncService; | ||
use Google\AdsApi\AdWords\v201806\cm\CampaignService; | ||
use Google\AdsApi\AdWords\v201806\cm\DateTimeRange; | ||
use Google\AdsApi\AdWords\v201806\cm\Paging; | ||
use Google\AdsApi\AdWords\v201806\cm\Selector; | ||
use Google\AdsApi\Common\OAuth2TokenBuilder; | ||
|
||
/** | ||
* 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. | ||
*/ | ||
class GetAccountChanges | ||
{ | ||
|
||
const PAGE_LIMIT = 500; | ||
|
||
public static function runExample( | ||
AdWordsServices $adWordsServices, | ||
AdWordsSession $session | ||
) { | ||
$campaignService = $adWordsServices->get($session, CampaignService::class); | ||
$customerSyncService = $adWordsServices->get($session, CustomerSyncService::class); | ||
|
||
// Create selector. | ||
$selector = new Selector(); | ||
$selector->setFields(['Id']); | ||
$selector->setPaging(new Paging(0, self::PAGE_LIMIT)); | ||
|
||
// Get an array of all campaign IDs. | ||
$campaignIds = []; | ||
$totalNumEntries = 0; | ||
do { | ||
$page = $campaignService->get($selector); | ||
|
||
if ($page->getEntries() !== null) { | ||
$totalNumEntries = $page->getTotalNumEntries(); | ||
foreach ($page->getEntries() as $campaign) { | ||
$campaignIds[] = $campaign->getId(); | ||
} | ||
} | ||
|
||
// Advance the paging index. | ||
$selector->getPaging()->setStartIndex( | ||
$selector->getPaging()->getStartIndex() + self::PAGE_LIMIT | ||
); | ||
} while ($selector->getPaging()->getStartIndex() < $totalNumEntries); | ||
|
||
// Set the date time range, from 24 hours ago until now. | ||
$dateTimeRange = new DateTimeRange(); | ||
$dateTimeRange->setMin(date('Ymd his', strtotime('-1 day'))); | ||
$dateTimeRange->setMax(date('Ymd his')); | ||
|
||
// Create selector. | ||
$selector = new CustomerSyncSelector(); | ||
$selector->setDateTimeRange($dateTimeRange); | ||
$selector->setCampaignIds($campaignIds); | ||
|
||
// Retrieve the account changes from the server. | ||
$accountChanges = $customerSyncService->get($selector); | ||
|
||
// Print out some information related to the account changes. | ||
if ($accountChanges !== null) { | ||
printf( | ||
"Most recent change: %s\n", | ||
$accountChanges->getLastChangeTimestamp() | ||
); | ||
if ($accountChanges->getChangedCampaigns() !== null) { | ||
foreach ($accountChanges->getChangedCampaigns() as $campaignChangeData) { | ||
printf( | ||
"Campaign with ID %d has change status '%s'.\n", | ||
$campaignChangeData->getCampaignId(), | ||
$campaignChangeData->getCampaignChangeStatus() | ||
); | ||
if ($campaignChangeData->getCampaignChangeStatus() !== ChangeStatus::NEW_VALUE) { | ||
printf( | ||
"\tAdded campaign criteria: %s\n", | ||
self::flatten($campaignChangeData->getAddedCampaignCriteria()) | ||
); | ||
printf( | ||
"\tRemoved campaign criteria: %s\n", | ||
self::flatten($campaignChangeData->getRemovedCampaignCriteria()) | ||
); | ||
if ($campaignChangeData->getChangedAdGroups() !== null) { | ||
foreach ($campaignChangeData->getChangedAdGroups() as $adGroupChangeData) { | ||
printf( | ||
"\tAd Group with ID %d has change status '%s'.\n", | ||
$adGroupChangeData->getAdGroupId(), | ||
$adGroupChangeData->getAdGroupChangeStatus() | ||
); | ||
if ($adGroupChangeData->getAdGroupChangeStatus() !== ChangeStatus::NEW_VALUE) { | ||
printf( | ||
"\t\tChanged ads: %s\n", | ||
self::flatten($adGroupChangeData->getChangedAds()) | ||
); | ||
printf( | ||
"\t\tChanged criteria: %s\n", | ||
self::flatten($adGroupChangeData->getChangedCriteria()) | ||
); | ||
printf( | ||
"\t\tRemoved criteria: %s\n", | ||
self::flatten($adGroupChangeData->getRemovedCriteria()) | ||
); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} else { | ||
print "No changes were found.\n"; | ||
} | ||
} | ||
|
||
/** | ||
* Flatten an array to a comma-separated string or empty string if the array | ||
* is null. | ||
* | ||
* @param array|null $array the array to be flattened | ||
* @return string the comma-separated string or empty string | ||
*/ | ||
private static function flatten($array) | ||
{ | ||
return ($array === null) ? '' : implode(', ', $array); | ||
} | ||
|
||
public static function main() | ||
{ | ||
// Generate a refreshable OAuth2 credential for authentication. | ||
$oAuth2Credential = (new OAuth2TokenBuilder())->fromFile()->build(); | ||
|
||
// Construct an API session configured from a properties file and the | ||
// OAuth2 credentials above. | ||
$session = (new AdWordsSessionBuilder())->fromFile()->withOAuth2Credential($oAuth2Credential)->build(); | ||
self::runExample(new AdWordsServices(), $session); | ||
} | ||
} | ||
|
||
GetAccountChanges::main(); |
Oops, something went wrong.