My favorites | Sign in
Google
             
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/perl
#
# Copyright 2009, 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.
#
# This code sample creates a new campaign with ad scheduling.

use strict;
use warnings;
use English '-no_match_vars';
use SOAP::Lite;

binmode(STDOUT, ':utf8');

# Provide AdWords login information.
my $email = 'INSERT_LOGIN_EMAIL_HERE';
my $password = 'INSERT_PASSWORD_HERE';
my $client_email = 'INSERT_CLIENT_LOGIN_EMAIL_HERE';
my $useragent = 'INSERT_COMPANY_NAME_HERE: AdWords API Perl Sample Code';
my $developer_token = 'INSERT_DEVELOPER_TOKEN_HERE';
my $application_token = 'INSERT_APPLICATION_TOKEN_HERE';

# Set up service connection with autotyping disabled and fault handler
# registered. To send requests to production environment, replace "sandbox" with
# "adwords". To view XML request/response, uncomment
# "SOAP::Lite->import(+trace => 'debug');".
my $url = sprintf('https://%s.google.com/api/adwords/v13/CampaignService',
'sandbox');
my $wsdl = $url . '?wsdl';
my $service = SOAP::Lite->service($wsdl)->autotype(0)->readable(1)->proxy($url);
$service->on_fault(sub {
my $response = $ARG[1];
die('The following SOAP fault occurred:', "\n",
' faultcode: ', $response->faultcode(), "\n",
' faultstring: ', $response->faultstring(), "\n")
});
# SOAP::Lite->import(+trace => 'debug');

# Define SOAP headers.
my @headers = (
SOAP::Header->name('email' => $email),
SOAP::Header->name('password' => $password),
SOAP::Header->name('clientEmail' => $client_email),
SOAP::Header->name('useragent' => $useragent),
SOAP::Header->name('developerToken' => $developer_token),
SOAP::Header->name('applicationToken' => $application_token)
);

# Create new campaign structure with ad scheduling set to show ads on Monday,
# Wednesday, and Friday from 8:00 a.m. to 5:00 p.m. Each bid is multiplied by
# 1.0.
my @days = qw(Monday Wednesday Friday);
my %interval_template = (
'endHour' => 17,
'endMinute' => 0,
'multiplier' => '1.0',
'startHour' => 8,
'startMinute' => 0
);
my @intervals;

foreach my $day (@days) {
$interval_template{'day'} = $day;
push(@intervals, {%interval_template});
}

my $schedule = {
'intervals' => \@intervals,
'status' => 'Enabled'
};
my $campaign = SOAP::Data->name('campaign' => {
'name' => 'Sample Campaign',
'budgetAmount' => 100000,
'budgetPeriod' => 'Daily',
'geoTargeting' => {'countryTargets' => {'countries' => ['US']}},
'languageTargeting' => {'languages' => ['en']},
'schedule' => $schedule
});

# Add campaign.
$campaign = $service->call('addCampaign' => $campaign, @headers)->result();

# Display new campaign.
print('New campaign with name "', $campaign->{'name'}, '" and id "',
$campaign->{'id'}, '" was created.', "\n");
Show details Hide details

Change log

r5 by api.jeffy on Mar 05, 2009   Diff
Updated code samples for v13 of the
AdWords API.
Go to: 
Project members, sign in to write a code review

Older revisions

r4 by api.jeffy on Aug 12, 2008   Diff
Updates for v12 of the API, and
additions of code samples that were
previously not written.
r2 by api.jeffy on Mar 13, 2008   Diff
Initial release of the Perl sample
AdWords API code. More samples to
come.
All revisions of this file

File info

Size: 3358 bytes, 96 lines

File properties

svn:executable
*