PHP API v201109 - Set scheduling for campaign

278 views
Skip to first unread message

Alistair Austen

unread,
Jan 25, 2012, 4:20:56 AM1/25/12
to adwor...@googlegroups.com
Hi,

Does anyone have a code snippet to show how to set the schedule for a campaign?  For example I need to set the campaign to run;

Mon-Thurs 7am-8pm
Fri 7am-5pm
Sat-Sun Not run

I've looked through the examples included in the API and didn't spot this one and also found another reference to this question in the forum but the content the answer links to doesn't exist anymore.

Many thanks in advance,

Alistair

Alistair Austen

unread,
Jan 25, 2012, 5:27:04 AM1/25/12
to adwor...@googlegroups.com
Sorry should have added code in PHP please...

Kevin Winter

unread,
Jan 27, 2012, 9:43:40 AM1/27/12
to adwor...@googlegroups.com
Hi Alistair,
  Unfortunately, we don't have an example in the client libraries to cover this use case.  We do have an article with Java code snippets - the PHP version should be pretty similar: http://code.google.com/apis/adwords/docs/guides/ad_scheduling.html

- Kevin Winter
AdWords API Team

Evgeniy Bogdanov

unread,
Jan 27, 2012, 11:25:11 AM1/27/12
to AdWords API Forum
I've created code for you (it assumes that file located in lib/
examples/v201109/ directory:

<?php
error_reporting(E_STRICT | E_ALL);

// You can set the include path to src directory or reference
// AdWordsUser.php directly via require_once.
// $path = '/path/to/aw_api_php_lib/src';
$path = dirname(__FILE__) . '/../../src';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);

require_once 'Google/Api/Ads/AdWords/Lib/AdWordsUser.php';

try {
// Get AdWordsUser from credentials in "../auth.ini"
// relative to the AdWordsUser.php file's directory.
$user = new AdWordsUser();

// Log SOAP XML request and response.
$user->LogDefaults();

// Get the CampaignCriterionService.
$campaignCriterionService =
$user->GetService('CampaignTargetService', 'v201109');

$campaignId = 'INSERT_CAMPAIGN_ID_HERE;

$bidMutliplier = 1.0; // This mean that we should use usual bid
$adScheduleDays = array();
// Mon-Thur 7 a.m - 8.pm
foreach(array('MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY') as $day)
{
$adScheduleDays[] = new AdScheduleTarget($day, 7, 'ZERO', 20,
'ZERO', $bidMutliplier);
}
// Fri 7 am - 5 pm
$adScheduleDays[] = new AdScheduleTarget('FRIDAY', 7, 'ZERO',
17,'ZERO', $bidMutliplier);
// Sat, sun - not run
// Do not set it at all

$adSchedule = array();
$adSchedule[] = new AdScheduleTargetList($adScheduleDays,
$campaignId);

// 'SET' new schedule operations. (Not ADD)
$operations = array();
foreach ($adSchedule as $adScheduleOperation) {
$operations[] = new
CampaignTargetOperation($adScheduleOperation, 'SET');
}

// Make the mutate request.
$result = $campaignCriterionService->mutate($operations);
var_dump($result);
} catch (Exception $e) {
print $e->getMessage();
}
?>

Alistair Austen

unread,
Jan 30, 2012, 7:22:28 AM1/30/12
to adwor...@googlegroups.com
That's great, thank you!

Alistair
Reply all
Reply to author
Forward
0 new messages