Forbidden access to V13 full samples!!!

36 views
Skip to first unread message

Peter Trobec

unread,
Nov 2, 2010, 6:15:42 AM11/2/10
to AdWords API Forum
Hello!

Since I can't make a report definition with the cross-client support
enabled on the new version of the API I have to use the V13 version.

I was looking through the examples, but when I click the View full
sample link it gives me following error:

Forbidden
Your client does not have permission to get URL /p/adwords-api-php-
samples/source/browse/trunk/src/schedule_report.php from this server.

Can someone please paste me the contents of the file or if the google
team can sort this thing out. It's a bit foolish to completely disband
the V13 support while not having the important functions implemented
in the new version.

Thank you,
Peter Trobec

Peter Trobec

unread,
Nov 3, 2010, 6:12:54 AM11/3/10
to adwor...@googlegroups.com
Since there was no answer since yesterday...I'd really appreciate if someone would post me a full example with authentication for the V13 ReportService with the crossClient option.

Thanks,
Peter Trobec

Peter Trobec

unread,
Nov 3, 2010, 9:42:13 AM11/3/10
to adwor...@googlegroups.com
Oh...finally figured something out, I always forgot to include the headers, but it's still not working:

<?

$email = "MyMail";
$password = "MyPass";
$useragent = "Wowca test sample";
$applicationToken = "ignored";
$account_type = "GOOGLE";
$service = "adwords";
$clientEmail = "client_1+$email";
$namespace = 'https://sandbox.google.com/api/adwords/v13';
$developerToken = "$email++USD";

$headers ='<email>'.$email.'</email>'.'<password>'.$password.'</password>'.
'<clientEmail>'.$clientEmail.'</clientEmail>'.
'<useragent>'.$useragent.'</useragent>'.
'<developerToken>'.$developerToken.'</developerToken>'.
'<applicationToken>'.$applicationToken.'</applicationToken>';

$report_service = SoapClientFactory::GetClient($namespace .
'/ReportService?wsdl', 'wsdl');
$report_service->setHeaders($headers);
$report_job =
  '<selectedReportType>Campaign</selectedReportType>'.
  '<name>Sample Keyword Report</name>'.
  '<crossClient>true</crossClient>'.
  '<clientEmails></clientEmails>'.
  '<aggregationTypes>Summary</aggregationTypes>'.
  '<adWordsType>ContentOnly</adWordsType>'.
  '<keywordType>Broad</keywordType>'.
  '<startDay>2010-10-01</startDay>'.
  '<endDay>2010-10-22</endDay>'.
  '<selectedColumns>Campaign</selectedColumns>'.
  '<selectedColumns>AdGroup</selectedColumns>'.
  '<selectedColumns>Keyword</selectedColumns>'.
  '<selectedColumns>Impressions</selectedColumns>'.
  '<selectedColumns>Clicks</selectedColumns>'.
  '<selectedColumns>CTR</selectedColumns>'.
  '<selectedColumns>AveragePosition</selectedColumns>'.
  '<campaigns>1</campaigns>';
$request_xml =
  '<validateReportJob>'.
  '<job xmlns:impl="https://adwords.google.com/api/adwords/v13"; '.
  'xsi:type="impl:DefinedReportJob">'.$report_job.'</job>'.
  '</validateReportJob>';


$report_service->call('validateReportJob', $request_xml);
print '<pre>';print_r($report_service);exit;
$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'];
print '<pre>';print_r($job_id);exit;
$request_xml =
'<getReportJobStatus>'.
'<reportJobId>'.$job_id.'</reportJobId>'.
'</getReportJobStatus>';
$status = $report_service->call('getReportJobStatus', $request_xml);
$status = $status['getReportJobStatusReturn'];
print '<pre>';print_r($status);exit;
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 ($status == 'Failed') {
  echo 'Report job generation failed.' . "\n";
  return;}

$request_xml =
  '<getGzipReportDownloadUrl>'.
  '<reportJobId>'.$job_id.'</reportJobId>'.
  '</getGzipReportDownloadUrl>';

$report_url = $report_service->call('getGzipReportDownloadUrl',
$request_xml);
$report_url = $report_url['getGzipReportDownloadUrlReturn'];
print '<pre>';print_r($report_url);exit;
?>

And I get this output:

ďťż

I just don't understand anything anymore... :D

Thanks,
Peter Trobec

Peter Trobec

unread,
Nov 3, 2010, 9:47:21 AM11/3/10
to adwor...@googlegroups.com
Ok, changed the namespace to: $namespace = 'https://adwords.google.com/api/adwords/cm/v201008';

and report service to: $report_service = SoapClientFactory::GetClient($namespace .
'/AdExtensionOverrideService?wsdl');

but it's still not working...still the same output.

Any ideas?

Peter Trobec

AdWords API Advisor

unread,
Nov 3, 2010, 1:11:22 PM11/3/10
to AdWords API Forum
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>';
$request_xml =
'<validateReportJob>' .
'<job xmlns:impl="https://adwords.google.com/api/adwords/v13" ' .
'xsi:type="impl:DefinedReportJob">' .
$report_job .
'</job>' .
'</validateReportJob>';

# 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);
}
?>

Peter Trobec

unread,
Nov 4, 2010, 4:34:00 AM11/4/10
to adwor...@googlegroups.com
Hey Eric!

Thanks for the reply, but I still have some problems...Can I use the new AdWordsSoapFactory or do i need the old one? Because all I get now is a blank page...

Thank you!
Peter Trobec

AdWords API Advisor

unread,
Nov 4, 2010, 5:56:42 PM11/4/10
to AdWords API Forum
Hi Peter,

This code isn't compatible with the new PHP client library, you'll
have to use the old SoapClientFactory code or replace it with a direct
call to the SOAP library of your choice.

- Eric

Peter Trobec

unread,
Nov 5, 2010, 4:00:08 AM11/5/10
to adwor...@googlegroups.com
Hi Eric,

Aha, OK, I understand now...can you please post me the SoapClientFactory code also, since I can't access it anywhere on the google pages.

Thank you,
Peter Trobec

AdWords API Advisor

unread,
Nov 9, 2010, 10:39:01 AM11/9/10
to AdWords API Forum
Hi Peter,

The SoapClientFactory code is below.

Best,
- Eric

<?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.

/**
* A helper class for instantiating NuSOAP, regardless of the PHP
version in
* use. In PHP5, a php_soap extension was introduced with a new class
named
* 'soapclient'. As a result, the NuSOAP library renamed its class to
* 'nusoap_client'.
*/

require_once('/usr/lib/php/nusoap.php');


class SoapClientFactory{
public static function GetClient(
$endpoint, $wsdl = false, $proxyhost = false, $proxyport =
false,
$proxyusername = false, $proxypassword = false, $timeout = 0,
$response_timeout = 30) {
if (!extension_loaded('soap')) {
return new soapclient($endpoint, $wsdl, $proxyhost, $proxyport,
$proxyusername, $proxypassword, $timeout, $response_timeout);
} else {
return new nusoap_client($endpoint, $wsdl, $proxyhost,
$proxyport,
$proxyusername, $proxypassword, $timeout, $response_timeout);

Peter Trobec

unread,
Dec 2, 2010, 8:24:31 AM12/2/10
to adwor...@googlegroups.com
Thank you for the answer! It works...in a way :)
Reply all
Reply to author
Forward
0 new messages