Skip to content

Commit 3a2249a

Browse files
committed
Release 35.2.0.
1 parent eeacf8a commit 3a2249a

File tree

1,346 files changed

+348192
-1473
lines changed

Some content is hidden

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

1,346 files changed

+348192
-1473
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
### 35.2.0
2+
3+
##### AdWords
4+
5+
* Added support and examples for v201806.
6+
17
### 35.1.0
28

39
##### DFP

examples/AdWords/v201802/BasicOperations/GetCampaignsWithAwql.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ public static function runExample(
4040
AdWordsServices $adWordsServices,
4141
AdWordsSession $session
4242
) {
43-
$campaignService = $adWordsServices->get($session,
44-
CampaignService::class);
43+
$campaignService = $adWordsServices->get(
44+
$session,
45+
CampaignService::class
46+
);
4547

4648
// Create AWQL query.
4749
$query = (new ServiceQueryBuilder())
@@ -51,7 +53,6 @@ public static function runExample(
5153
->build();
5254

5355
do {
54-
5556
// Advance the paging offset in subsequent iterations only.
5657
if (isset($page)) {
5758
$query->nextPage();
@@ -73,8 +74,10 @@ public static function runExample(
7374
}
7475
} while ($query->hasNext($page));
7576

76-
printf("Number of results found: %d\n",
77-
$page->getTotalNumEntries());
77+
printf(
78+
"Number of results found: %d\n",
79+
$page->getTotalNumEntries()
80+
);
7881
}
7982

8083
public static function main()
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
/**
3+
* Copyright 2017 Google Inc. All Rights Reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
namespace Google\AdsApi\Examples\AdWords\v201806\AccountManagement;
19+
20+
require __DIR__ . '/../../../../vendor/autoload.php';
21+
22+
use Google\AdsApi\AdWords\AdWordsServices;
23+
use Google\AdsApi\AdWords\AdWordsSession;
24+
use Google\AdsApi\AdWords\AdWordsSessionBuilder;
25+
use Google\AdsApi\AdWords\v201806\cm\Operator;
26+
use Google\AdsApi\AdWords\v201806\mcm\CustomerService;
27+
use Google\AdsApi\AdWords\v201806\mcm\ServiceLink;
28+
use Google\AdsApi\AdWords\v201806\mcm\ServiceLinkLinkStatus;
29+
use Google\AdsApi\AdWords\v201806\mcm\ServiceLinkOperation;
30+
use Google\AdsApi\AdWords\v201806\mcm\ServiceType;
31+
use Google\AdsApi\Common\OAuth2TokenBuilder;
32+
33+
/**
34+
* This example accepts a pending invitation to link your AdWords account to a
35+
* Google Merchant Center account.
36+
*/
37+
class AcceptServiceLink
38+
{
39+
40+
const SERVICE_LINK_ID = 'INSERT_SERVICE_LINK_ID_HERE';
41+
42+
public static function runExample(
43+
AdWordsServices $adWordsServices,
44+
AdWordsSession $session,
45+
$serviceLinkId
46+
) {
47+
$customerService = $adWordsServices->get($session, CustomerService::class);
48+
49+
// Create service link.
50+
$serviceLink = new ServiceLink();
51+
$serviceLink->setServiceLinkId($serviceLinkId);
52+
$serviceLink->setServiceType(ServiceType::MERCHANT_CENTER);
53+
$serviceLink->setLinkStatus(ServiceLinkLinkStatus::ACTIVE);
54+
55+
// Create a service link operation and add it to the list.
56+
$operations = [];
57+
$operation = new ServiceLinkOperation();
58+
$operation->setOperator(Operator::SET);
59+
$operation->setOperand($serviceLink);
60+
$operations[] = $operation;
61+
62+
// Accept service links on the server and print out some information about
63+
// accepted service links.
64+
$serviceLinks = $customerService->mutateServiceLinks($operations);
65+
foreach ($serviceLinks as $serviceLink) {
66+
printf(
67+
"Service link with service link ID %d and type '%s' updated to status: %s.\n",
68+
$serviceLink->getServiceLinkId(),
69+
$serviceLink->getServiceType(),
70+
$serviceLink->getLinkStatus()
71+
);
72+
}
73+
}
74+
75+
public static function main()
76+
{
77+
// Generate a refreshable OAuth2 credential for authentication.
78+
$oAuth2Credential = (new OAuth2TokenBuilder())->fromFile()->build();
79+
80+
// Construct an API session configured from a properties file and the
81+
// OAuth2 credentials above.
82+
$session = (new AdWordsSessionBuilder())->fromFile()->withOAuth2Credential($oAuth2Credential)->build();
83+
self::runExample(
84+
new AdWordsServices(),
85+
$session,
86+
intval(self::SERVICE_LINK_ID)
87+
);
88+
}
89+
}
90+
91+
AcceptServiceLink::main();
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
/**
3+
* Copyright 2017 Google Inc. All Rights Reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
namespace Google\AdsApi\Examples\AdWords\v201806\AccountManagement;
19+
20+
require __DIR__ . '/../../../../vendor/autoload.php';
21+
22+
use Google\AdsApi\AdWords\AdWordsServices;
23+
use Google\AdsApi\AdWords\AdWordsSession;
24+
use Google\AdsApi\AdWords\AdWordsSessionBuilder;
25+
use Google\AdsApi\AdWords\v201806\cm\Operator;
26+
use Google\AdsApi\AdWords\v201806\mcm\ManagedCustomer;
27+
use Google\AdsApi\AdWords\v201806\mcm\ManagedCustomerOperation;
28+
use Google\AdsApi\AdWords\v201806\mcm\ManagedCustomerService;
29+
use Google\AdsApi\Common\OAuth2TokenBuilder;
30+
31+
/**
32+
* This example creates a new account under an AdWords manager account. Note:
33+
* this example must be run using the credentials of an AdWords manager account,
34+
* and by default the new account will only be accessible via the parent AdWords
35+
* manager account.
36+
*/
37+
class CreateAccount
38+
{
39+
40+
public static function runExample(
41+
AdWordsServices $adWordsServices,
42+
AdWordsSession $session
43+
) {
44+
$managedCustomerService = $adWordsServices->get(
45+
$session,
46+
ManagedCustomerService::class
47+
);
48+
49+
// Create a managed customer.
50+
$customer = new ManagedCustomer();
51+
$customer->setName('Account #' . uniqid());
52+
$customer->setCurrencyCode('EUR');
53+
$customer->setDateTimeZone('Europe/London');
54+
55+
// Create a managed customer operation and add it to the list.
56+
$operations = [];
57+
$operation = new ManagedCustomerOperation();
58+
$operation->setOperator(Operator::ADD);
59+
$operation->setOperand($customer);
60+
// For whitelisted users only, uncomment two below commands to invite a
61+
// user to have access to an account on an ADD. An email will be sent to
62+
// that user inviting them to have access to the newly created account.
63+
// $operation->setInviteeEmail('[email protected]');
64+
// $operation->setInviteeRole('ADMINISTRATIVE');
65+
66+
$operations[] = $operation;
67+
// Create a managed customer on the server and print out some info
68+
// about it.
69+
$customer = $managedCustomerService->mutate($operations)->getValue()[0];
70+
printf(
71+
"Account with customer ID %d was created.\n",
72+
$customer->getCustomerId()
73+
);
74+
}
75+
76+
public static function main()
77+
{
78+
// Generate a refreshable OAuth2 credential for authentication.
79+
$oAuth2Credential = (new OAuth2TokenBuilder())->fromFile()->build();
80+
81+
// Construct an API session configured from a properties file and the
82+
// OAuth2 credentials above.
83+
// You can use withClientCustomerId() of AdWordsSessionBuilder to specify
84+
// your manager account ID under which you want to create an account.
85+
$session = (new AdWordsSessionBuilder())->fromFile()->withOAuth2Credential($oAuth2Credential)->build();
86+
self::runExample(new AdWordsServices(), $session);
87+
}
88+
}
89+
90+
CreateAccount::main();
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
<?php
2+
/**
3+
* Copyright 2017 Google Inc. All Rights Reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
namespace Google\AdsApi\Examples\AdWords\v201806\AccountManagement;
19+
20+
require __DIR__ . '/../../../../vendor/autoload.php';
21+
22+
use Google\AdsApi\AdWords\AdWordsServices;
23+
use Google\AdsApi\AdWords\AdWordsSession;
24+
use Google\AdsApi\AdWords\AdWordsSessionBuilder;
25+
use Google\AdsApi\AdWords\v201806\ch\ChangeStatus;
26+
use Google\AdsApi\AdWords\v201806\ch\CustomerSyncSelector;
27+
use Google\AdsApi\AdWords\v201806\ch\CustomerSyncService;
28+
use Google\AdsApi\AdWords\v201806\cm\CampaignService;
29+
use Google\AdsApi\AdWords\v201806\cm\DateTimeRange;
30+
use Google\AdsApi\AdWords\v201806\cm\Paging;
31+
use Google\AdsApi\AdWords\v201806\cm\Selector;
32+
use Google\AdsApi\Common\OAuth2TokenBuilder;
33+
34+
/**
35+
* This example gets the changes in the account during the last 24 hours.
36+
* Note: this example must be run using the credentials of an ad-serving
37+
* account.
38+
*/
39+
class GetAccountChanges
40+
{
41+
42+
const PAGE_LIMIT = 500;
43+
44+
public static function runExample(
45+
AdWordsServices $adWordsServices,
46+
AdWordsSession $session
47+
) {
48+
$campaignService = $adWordsServices->get($session, CampaignService::class);
49+
$customerSyncService = $adWordsServices->get($session, CustomerSyncService::class);
50+
51+
// Create selector.
52+
$selector = new Selector();
53+
$selector->setFields(['Id']);
54+
$selector->setPaging(new Paging(0, self::PAGE_LIMIT));
55+
56+
// Get an array of all campaign IDs.
57+
$campaignIds = [];
58+
$totalNumEntries = 0;
59+
do {
60+
$page = $campaignService->get($selector);
61+
62+
if ($page->getEntries() !== null) {
63+
$totalNumEntries = $page->getTotalNumEntries();
64+
foreach ($page->getEntries() as $campaign) {
65+
$campaignIds[] = $campaign->getId();
66+
}
67+
}
68+
69+
// Advance the paging index.
70+
$selector->getPaging()->setStartIndex(
71+
$selector->getPaging()->getStartIndex() + self::PAGE_LIMIT
72+
);
73+
} while ($selector->getPaging()->getStartIndex() < $totalNumEntries);
74+
75+
// Set the date time range, from 24 hours ago until now.
76+
$dateTimeRange = new DateTimeRange();
77+
$dateTimeRange->setMin(date('Ymd his', strtotime('-1 day')));
78+
$dateTimeRange->setMax(date('Ymd his'));
79+
80+
// Create selector.
81+
$selector = new CustomerSyncSelector();
82+
$selector->setDateTimeRange($dateTimeRange);
83+
$selector->setCampaignIds($campaignIds);
84+
85+
// Retrieve the account changes from the server.
86+
$accountChanges = $customerSyncService->get($selector);
87+
88+
// Print out some information related to the account changes.
89+
if ($accountChanges !== null) {
90+
printf(
91+
"Most recent change: %s\n",
92+
$accountChanges->getLastChangeTimestamp()
93+
);
94+
if ($accountChanges->getChangedCampaigns() !== null) {
95+
foreach ($accountChanges->getChangedCampaigns() as $campaignChangeData) {
96+
printf(
97+
"Campaign with ID %d has change status '%s'.\n",
98+
$campaignChangeData->getCampaignId(),
99+
$campaignChangeData->getCampaignChangeStatus()
100+
);
101+
if ($campaignChangeData->getCampaignChangeStatus() !== ChangeStatus::NEW_VALUE) {
102+
printf(
103+
"\tAdded campaign criteria: %s\n",
104+
self::flatten($campaignChangeData->getAddedCampaignCriteria())
105+
);
106+
printf(
107+
"\tRemoved campaign criteria: %s\n",
108+
self::flatten($campaignChangeData->getRemovedCampaignCriteria())
109+
);
110+
if ($campaignChangeData->getChangedAdGroups() !== null) {
111+
foreach ($campaignChangeData->getChangedAdGroups() as $adGroupChangeData) {
112+
printf(
113+
"\tAd Group with ID %d has change status '%s'.\n",
114+
$adGroupChangeData->getAdGroupId(),
115+
$adGroupChangeData->getAdGroupChangeStatus()
116+
);
117+
if ($adGroupChangeData->getAdGroupChangeStatus() !== ChangeStatus::NEW_VALUE) {
118+
printf(
119+
"\t\tChanged ads: %s\n",
120+
self::flatten($adGroupChangeData->getChangedAds())
121+
);
122+
printf(
123+
"\t\tChanged criteria: %s\n",
124+
self::flatten($adGroupChangeData->getChangedCriteria())
125+
);
126+
printf(
127+
"\t\tRemoved criteria: %s\n",
128+
self::flatten($adGroupChangeData->getRemovedCriteria())
129+
);
130+
}
131+
}
132+
}
133+
}
134+
}
135+
}
136+
} else {
137+
print "No changes were found.\n";
138+
}
139+
}
140+
141+
/**
142+
* Flatten an array to a comma-separated string or empty string if the array
143+
* is null.
144+
*
145+
* @param array|null $array the array to be flattened
146+
* @return string the comma-separated string or empty string
147+
*/
148+
private static function flatten($array)
149+
{
150+
return ($array === null) ? '' : implode(', ', $array);
151+
}
152+
153+
public static function main()
154+
{
155+
// Generate a refreshable OAuth2 credential for authentication.
156+
$oAuth2Credential = (new OAuth2TokenBuilder())->fromFile()->build();
157+
158+
// Construct an API session configured from a properties file and the
159+
// OAuth2 credentials above.
160+
$session = (new AdWordsSessionBuilder())->fromFile()->withOAuth2Credential($oAuth2Credential)->build();
161+
self::runExample(new AdWordsServices(), $session);
162+
}
163+
}
164+
165+
GetAccountChanges::main();

0 commit comments

Comments
 (0)