Skip to content

Commit

Permalink
Release 25.4.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
vtsao committed Mar 3, 2017
1 parent 2a10692 commit aee308d
Show file tree
Hide file tree
Showing 32 changed files with 2,424 additions and 39 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
### 25.4.0

##### DFP

* Added `perform action` examples for core services.
* Added `CreateNativeCreatives` example.
* Fixed the `CreateProposals` example.
* Added some `update` examples for reconciliation services.

### 25.3.0

##### AdWords
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static function runExample(AdWordsServices $adWordsServices,
// Optional: You can set up to 10 image assets for your campaign.
// See UploadImage.php for an example on how to upload images.
//
// $universalAppSetting->imageMediaIds = array(INSERT_IMAGE_MEDIA_ID_HERE);
// $universalAppSetting->imageMediaIds = [INSERT_IMAGE_MEDIA_ID_HERE];

// Optimize this campaign for getting new users for your app.
$universalAppSetting->setUniversalAppBiddingStrategyGoalType(
Expand All @@ -123,10 +123,10 @@ public static function runExample(AdWordsServices $adWordsServices,
// Conversion type IDs can be retrieved using ConversionTrackerService.get.
//
// $campaign->selectiveOptimization = new SelectiveOptimization();
// $campaign->selectiveOptimization->conversionTypeIds = array(
// $campaign->selectiveOptimization->conversionTypeIds = [
// INSERT_CONVERSION_TYPE_ID_1_HERE,
// INSERT_CONVERSION_TYPE_ID_2_HERE
// );
// ];

// Optional: Set the campaign settings for Advanced location options.
$geoTargetTypeSetting = new GeoTargetTypeSetting();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static function runExample(AdWordsServices $adWordsServices,
// Optional: You can set up to 10 image assets for your campaign.
// See UploadImage.php for an example on how to upload images.
//
// $universalAppSetting->imageMediaIds = array(INSERT_IMAGE_MEDIA_ID_HERE);
// $universalAppSetting->imageMediaIds = [INSERT_IMAGE_MEDIA_ID_HERE];

// Optimize this campaign for getting new users for your app.
$universalAppSetting->setUniversalAppBiddingStrategyGoalType(
Expand All @@ -123,10 +123,10 @@ public static function runExample(AdWordsServices $adWordsServices,
// Conversion type IDs can be retrieved using ConversionTrackerService.get.
//
// $campaign->selectiveOptimization = new SelectiveOptimization();
// $campaign->selectiveOptimization->conversionTypeIds = array(
// $campaign->selectiveOptimization->conversionTypeIds = [
// INSERT_CONVERSION_TYPE_ID_1_HERE,
// INSERT_CONVERSION_TYPE_ID_2_HERE
// );
// ];

// Optional: Set the campaign settings for Advanced location options.
$geoTargetTypeSetting = new GeoTargetTypeSetting();
Expand Down
7 changes: 3 additions & 4 deletions examples/Dfp/v201702/CreativeService/CreateCreatives.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
use Google\AdsApi\Dfp\DfpServices;
use Google\AdsApi\Dfp\DfpSession;
use Google\AdsApi\Dfp\DfpSessionBuilder;
use Google\AdsApi\Dfp\v201702\Size;
use Google\AdsApi\Dfp\v201702\CreativeAsset;
use Google\AdsApi\Dfp\v201702\ImageCreative;
use Google\AdsApi\Dfp\v201702\CreativeService;
use Google\AdsApi\Dfp\v201702\ImageCreative;
use Google\AdsApi\Dfp\v201702\Size;

/**
* Creates image creatives.
Expand All @@ -40,8 +40,7 @@ class CreateCreatives {

public static function runExample(DfpServices $dfpServices,
DfpSession $session, $advertiserId) {
$creativeService =
$dfpServices->get($session, CreativeService::class);
$creativeService = $dfpServices->get($session, CreativeService::class);

$imageCreative = new ImageCreative();
$imageCreative->setName('Image creative #'. uniqid());
Expand Down
171 changes: 171 additions & 0 deletions examples/Dfp/v201702/CreativeService/CreateNativeCreatives.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
<?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\Dfp\v201702\CreativeService;

require '../../../../vendor/autoload.php';

use Google\AdsApi\Common\OAuth2TokenBuilder;
use Google\AdsApi\Dfp\DfpServices;
use Google\AdsApi\Dfp\DfpSession;
use Google\AdsApi\Dfp\DfpSessionBuilder;
use Google\AdsApi\Dfp\v201702\AssetCreativeTemplateVariableValue;
use Google\AdsApi\Dfp\v201702\CreativeAsset;
use Google\AdsApi\Dfp\v201702\CreativeService;
use Google\AdsApi\Dfp\v201702\Size;
use Google\AdsApi\Dfp\v201702\StringCreativeTemplateVariableValue;
use Google\AdsApi\Dfp\v201702\TemplateCreative;
use Google\AdsApi\Dfp\v201702\UrlCreativeTemplateVariableValue;

/**
* Creates native creatives.
*
* This example is meant to be run from a command line (not as a webpage) and
* requires that you've setup an `adsapi_php.ini` file in your home directory
* with your API credentials and settings. See `README.md` for more info.
*/
class CreateNativeCreatives {

const ADVERTISER_ID = 'INSERT_ADVERTISER_ID_HERE';

public static function runExample(DfpServices $dfpServices,
DfpSession $session, $advertiserId) {
$creativeService = $dfpServices->get($session, CreativeService::class);

// Use the system defined native app install creative template.
$nativeAppInstallTemplateId = 10004400;

// Use 1x1 as the size for native creatives.
$size = new Size();
$size->setWidth(1);
$size->setHeight(1);
$size->setIsAspectRatio(false);

// Create a native app install creative for the Pie Noon app.
$nativeAppInstallCreative = new TemplateCreative();
$nativeAppInstallCreative->setName('Native creative #' . uniqid());
$nativeAppInstallCreative->setAdvertiserId($advertiserId);
$nativeAppInstallCreative->setDestinationUrl(
'https://play.google.com/store/apps/details?id=com.google.fpl.pie_noon'
);
$nativeAppInstallCreative
->setCreativeTemplateId($nativeAppInstallTemplateId);
$nativeAppInstallCreative->setSize($size);

// Set the headline.
$headlineVariableValue = new StringCreativeTemplateVariableValue();
$headlineVariableValue->setUniqueName('Headline');
$headlineVariableValue->setValue('Pie Noon');
$variableValues = [$headlineVariableValue];

// Set the body text.
$bodyVariableValue = new StringCreativeTemplateVariableValue();
$bodyVariableValue->setUniqueName('Body');
$bodyVariableValue->setValue('Try multi-screen mode!');
$variableValues[] = $bodyVariableValue;

// Set the image asset.
$imageVariableValue = new AssetCreativeTemplateVariableValue();
$imageVariableValue->setUniqueName('Image');
$imageAsset = new CreativeAsset();
$imageAsset->setFileName('image' . uniqid() . '.png');
$imageAsset->setAssetByteArray(file_get_contents(
'https://lh4.ggpht.com/GIGNKdGHMEHFDw6TM2bgAUDKPQQRIReKZPqEpMeEhZOPYnTd'
. 'OQGaSpGSEZflIFs0iw=h300'
));
$imageVariableValue->setAsset($imageAsset);
$variableValues[] = $imageVariableValue;

// Set the price.
$priceVariableValue = new StringCreativeTemplateVariableValue();
$priceVariableValue->setUniqueName('Price');
$priceVariableValue->setValue('Free');
$variableValues[] = $priceVariableValue;

// Set app icon image asset.
$appIconVariableValue = new AssetCreativeTemplateVariableValue();
$appIconVariableValue->setUniqueName('Appicon');
$appIconAsset = new CreativeAsset();
$appIconAsset->setFileName('icon' . uniqid() . '.png');
$appIconAsset->setAssetByteArray(file_get_contents(
'https://lh6.ggpht.com/Jzvjne5CLs6fJ1MHF-XeuUfpABzl0YNMlp4RpHnvPRCIj4--'
. 'eTDwtyouwUDzVVekXw=w300'
));
$appIconVariableValue->setAsset($appIconAsset);
$variableValues[] = $appIconVariableValue;

// Set the call to action text.
$callToActionVariableValue = new StringCreativeTemplateVariableValue();
$callToActionVariableValue->setUniqueName('Calltoaction');
$callToActionVariableValue->setValue('Install');
$variableValues[] = $callToActionVariableValue;

// Set the star rating.
$starRatingVariableValue = new StringCreativeTemplateVariableValue();
$starRatingVariableValue->setUniqueName('Starrating');
$starRatingVariableValue->setValue('4');
$variableValues[] = $starRatingVariableValue;

// Set the store type.
$storeVariableValue = new StringCreativeTemplateVariableValue();
$storeVariableValue->setUniqueName('Store');
$storeVariableValue->setValue('Google Play');
$variableValues[] = $storeVariableValue;

// Set the deep link URL.
$deepLinkVariableValue = new UrlCreativeTemplateVariableValue();
$deepLinkVariableValue->setUniqueName('DeeplinkclickactionURL');
$deepLinkVariableValue
->setValue('market://details?id=com.google.fpl.pie_noon');
$variableValues[] = $deepLinkVariableValue;

$nativeAppInstallCreative
->setCreativeTemplateVariableValues($variableValues);

// Create the native creatives on the server.
$results = $creativeService->createCreatives([$nativeAppInstallCreative]);

// Print out some information for each created native creative.
foreach ($results as $i => $nativeAppInstallCreative) {
printf(
"%d) Native creative with ID %d and name '%s' was created and can be "
. "previewed at: '%s'.\n",
$i,
$nativeAppInstallCreative->getId(),
$nativeAppInstallCreative->getName(),
$nativeAppInstallCreative->getPreviewUrl()
);
}
}

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 DfpSessionBuilder())
->fromFile()
->withOAuth2Credential($oAuth2Credential)
->build();

self::runExample(new DfpServices(), $session, intval(self::ADVERTISER_ID));
}
}

CreateNativeCreatives::main();
3 changes: 1 addition & 2 deletions examples/Dfp/v201702/CreativeService/GetAllCreatives.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ class GetAllCreatives {

public static function runExample(DfpServices $dfpServices,
DfpSession $session) {
$creativeService =
$dfpServices->get($session, CreativeService::class);
$creativeService = $dfpServices->get($session, CreativeService::class);

// Create a statement to select creatives.
$pageSize = StatementBuilder::SUGGESTED_PAGE_LIMIT;
Expand Down
3 changes: 1 addition & 2 deletions examples/Dfp/v201702/CreativeService/GetImageCreatives.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ class GetImageCreatives {

public static function runExample(DfpServices $dfpServices,
DfpSession $session) {
$creativeService =
$dfpServices->get($session, CreativeService::class);
$creativeService = $dfpServices->get($session, CreativeService::class);

// Create a statement to select creatives.
$pageSize = StatementBuilder::SUGGESTED_PAGE_LIMIT;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?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\Dfp\v201702\CustomTargetingService;

require '../../../../vendor/autoload.php';

use Google\AdsApi\Common\OAuth2TokenBuilder;
use Google\AdsApi\Dfp\DfpServices;
use Google\AdsApi\Dfp\DfpSession;
use Google\AdsApi\Dfp\DfpSessionBuilder;
use Google\AdsApi\Dfp\Util\v201702\StatementBuilder;
use Google\AdsApi\Dfp\v201702\CustomTargetingService;
use Google\AdsApi\Dfp\v201702\DeleteCustomTargetingKeys as DeleteCustomTargetingKeysAction;

/**
* Deletes custom targeting keys.
*
* This example is meant to be run from a command line (not as a webpage) and
* requires that you've setup an `adsapi_php.ini` file in your home directory
* with your API credentials and settings. See `README.md` for more info.
*/
class DeleteCustomTargetingKeys {

const CUSTOM_TARGETING_KEY_ID = 'INSERT_CUSTOM_TARGETING_KEY_ID_HERE';

public static function runExample(DfpServices $dfpServices,
DfpSession $session, $customTargetingKeyId) {
$customTargetingService =
$dfpServices->get($session, CustomTargetingService::class);

// Create a statement to select the custom targeting keys to delete.
$pageSize = StatementBuilder::SUGGESTED_PAGE_LIMIT;
$statementBuilder = (new StatementBuilder())
->where('id = :id')
->orderBy('id ASC')
->limit($pageSize)
->withBindVariableValue('id', $customTargetingKeyId);

// Retrieve a small amount of custom targeting keys at a time, paging
// through until all custom targeting keys have been retrieved.
$totalResultSetSize = 0;
do {
$page = $customTargetingService->getCustomTargetingKeysByStatement(
$statementBuilder->toStatement());

// Print out some information for the custom targeting keys to be deleted.
if ($page->getResults() !== null) {
$totalResultSetSize = $page->getTotalResultSetSize();
$i = $page->getStartIndex();
foreach ($page->getResults() as $customTargetingKey) {
printf(
"%d) Custom targeting key with ID %d, " .
"name '%s', " .
"and display name '%s' will be deleted.\n",
$i++,
$customTargetingKey->getId(),
$customTargetingKey->getName(),
$customTargetingKey->getDisplayName()
);
}
}

$statementBuilder->increaseOffsetBy($pageSize);
} while ($statementBuilder->getOffset() < $totalResultSetSize);

printf("Total number of custom targeting keys to be deleted: %d\n",
$totalResultSetSize);

if ($totalResultSetSize > 0) {
// Remove limit and offset from statement so we can reuse the statement.
$statementBuilder->removeLimitAndOffset();

// Create and perform action.
$action = new DeleteCustomTargetingKeysAction();
$result = $customTargetingService->performCustomTargetingKeyAction(
$action, $statementBuilder->toStatement());

if ($result !== null && $result->getNumChanges() > 0) {
printf("Number of custom targeting keys deleted: %d\n",
$result->getNumChanges());
} else {
printf("No custom targeting keys were deleted.\n");
}
}
}

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 DfpSessionBuilder())
->fromFile()
->withOAuth2Credential($oAuth2Credential)
->build();

self::runExample(
new DfpServices(), $session, intval(self::CUSTOM_TARGETING_KEY_ID));
}
}

DeleteCustomTargetingKeys::main();
Loading

0 comments on commit aee308d

Please sign in to comment.