Hi Peter,
The old sample code projects have been deleted. I've pasted the v13
report service example below.
Best,
- Eric Koleda, AdWords API Team
<?php
// 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 retrieves a keyword report for the AdWords account
that
* belongs to the customer issuing the request.
*/
require_once('soapclientfactory.php');
# Provide AdWords login information.
$email = 'INSERT_LOGIN_EMAIL_HERE';
$password = 'INSERT_PASSWORD_HERE';
$client_email = 'INSERT_CLIENT_LOGIN_EMAIL_HERE';
$useragent = 'INSERT_COMPANY_NAME: AdWords API PHP Sample Code';
$developer_token = 'INSERT_DEVELOPER_TOKEN_HERE';
$application_token = 'INSERT_APPLICATION_TOKEN_HERE';
# Define SOAP headers.
$headers =
'<email>' . $email . '</email>'.
'<password>' . $password . '</password>' .
'<clientEmail>' . $client_email . '</clientEmail>' .
'<useragent>' . $useragent . '</useragent>' .
'<developerToken>' . $developer_token . '</developerToken>' .
'<applicationToken>' . $application_token . '</applicationToken>';
# Set up service connection. To view XML request/response, change
value of
# $debug to 1. To send requests to production environment, replace
# "
sandbox.google.com" with "
adwords.google.com".
$namespace = '
https://sandbox.google.com/api/adwords/v13';
$report_service =
SoapClientFactory::GetClient($namespace . '/ReportService?wsdl',
'wsdl');
$report_service->setHeaders($headers);
$debug = 0;
# BEGIN ReportService.validateReportJob,
ReportService.scheduleReportJob, ReportService.getReportJobStatus,
ReportService.getGzipReportDownloadUrl: v13-up
# Create report job structure.
$report_job =
'<selectedReportType>Keyword</selectedReportType>' .
'<name>Sample Keyword Report</name>' .
'<aggregationTypes>Summary</aggregationTypes>' .
'<adWordsType>SearchOnly</adWordsType>' .
'<keywordType>Broad</keywordType>' .
'<startDay>2008-01-01</startDay>' .
'<endDay>2008-01-31</endDay>' .
'<selectedColumns>Campaign</selectedColumns>' .
'<selectedColumns>AdGroup</selectedColumns>' .
'<selectedColumns>Keyword</selectedColumns>' .
'<selectedColumns>KeywordStatus</selectedColumns>' .
'<selectedColumns>KeywordMinCPC</selectedColumns>' .
'<selectedColumns>KeywordDestUrlDisplay</selectedColumns>' .
'<selectedColumns>Impressions</selectedColumns>' .
'<selectedColumns>Clicks</selectedColumns>' .
'<selectedColumns>CTR</selectedColumns>' .
'<selectedColumns>AveragePosition</selectedColumns>';
# Validate report.
$report_service->call('validateReportJob', $request_xml);
if ($debug) show_xml($report_service);
if ($report_service->fault) show_fault($report_service);
# Schedule report.
$request_xml =
'<scheduleReportJob>' .
'<job xmlns:impl="
https://adwords.google.com/api/adwords/v13" ' .
'xsi:type="impl:DefinedReportJob">' .
$report_job .
'</job>' .
'</scheduleReportJob>';
$job_id = $report_service->call('scheduleReportJob', $request_xml);
$job_id = $job_id['scheduleReportJobReturn'];
if ($debug) show_xml($report_service);
if ($report_service->fault) show_fault($service);
# Wait for report to finish.
$request_xml =
'<getReportJobStatus>' .
'<reportJobId>' .
$job_id .
'</reportJobId>' .
'</getReportJobStatus>';
$status = $report_service->call('getReportJobStatus', $request_xml);
$status = $status['getReportJobStatusReturn'];
if ($debug) show_xml($report_service);
if ($report_service->fault) show_fault($service);
while ($status != 'Completed' and $status != 'Failed') {
echo 'Report job status is "' . $status . '".' . "\n";
sleep(30);
$status = $report_service->call('getReportJobStatus', $request_xml);
$status = $status['getReportJobStatusReturn'];
if ($debug) show_xml($report_service);
if ($report_service->fault) show_fault($service);
}
if ($status == 'Failed') {
echo 'Report job generation failed.' . "\n";
return;
}
# Download report.
$request_xml =
'<getGzipReportDownloadUrl>' .
'<reportJobId>' .
$job_id .
'</reportJobId>' .
'</getGzipReportDownloadUrl>';
$report_url = $report_service->call('getGzipReportDownloadUrl',
$request_xml);
$report_url = $report_url['getGzipReportDownloadUrlReturn'];
# END ReportService.validateReportJob,
ReportService.scheduleReportJob, ReportService.getReportJobStatus,
ReportService.getGzipReportDownloadUrl: v13-up
if ($debug) show_xml($report_service);
if ($report_service->fault) show_fault($service);
echo 'Report is available at "' . $report_url . '".' . "\n";
function show_xml($service) {
echo $service->request;
echo $service->response;
echo "\n";
}
function show_fault($service) {
echo "\n";
echo 'Fault: ' . $service->fault . "\n";
echo 'Code: ' . $service->faultcode . "\n";
echo 'String: ' . $service->faultstring . "\n";
echo 'Detail: ' . $service->faultdetail . "\n";
exit(0);
}
?>