I've been trying to get this working, but I always get internal server error. It's working fine if I request "generateReport" or something else, but with "generateAdCode" not. My code:
<?php
// Copyright 2006, Google Inc. All rights reserved.
/**
* sample code to generate AFC aggregate report through Adsense API
*/
require_once('lib/nusoap.php');
require_once('common.php');
$server = 'https://sandbox.google.com';
$namespace = 'http://www.google.com/api/adsense/v2';
// Set up the authentication headers
$email = '<impl:developer_email>MY DEVELOPER EMAIL</impl:developer_email>';
$password = '<impl:developer_password>MY DEVELOPER PW</impl:developer_password>';
$client_id = '<impl:client_id>ca-pub-1744271982572164</impl:client_id>';
$synServiceId = 123;
$header = $email . $password . $client_id;
// Set up client soap for webservice
$wsdl = 'https://sandbox.google.com/api/adsense/v2/AdSenseForContentService?wsdl';
$client = new nusoapclient($wsdl, true);
$err = $client->getError();
if ($err) {
showSoapClientError($err);
return;
}
$client->soap_defencoding = 'UTF-8';
// Set the headers; they are needed for authentication
$client->setHeaders($header);
if ($client->fault) {
showMyErrors($client);
return;
}
$err = $client->getError();
if ($err) {
showSoapClientError($err);
return;
}
// setting up adstyle parameter
$ads_param = '<adStyle>';
$ads_param .= '<backgroundColor>#FFFFFF</backgroundColor>';
$ads_param .= '<borderColor>#0000FF</borderColor>';
$ads_param .= "<name>demoStyle</name>";
$ads_param .= '<textColor>#00FF00</textColor>';
$ads_param .= '<titleColor>#FF0000</titleColor>';
$ads_param .= '<urlColor>#FFFF00</urlColor>';
$ads_param .= '</adStyle>';
// setting up parameter
$param = '<synServiceId>'.$synServiceId.'</synServiceId>';
$param .= $ads_param;
$param .= '<adUnitType><value>TextOnly</value></adUnitType>';
$param .= '<layout><value>728x90</value></layout>';
$param .= '<alternate>#FFFFFF</alternate>';
$param .= '<isFramedPage>false</isFramedPage>';
$param .= '<cornerStyles><value>DEFAULT</value></cornerStyles>';
$param .= '<channelName xsi:nil="true"/>';
$param = "<ns1:generateAdCode xmlns:ns1=\"$namespace\">" . $param . "</ns1:generateAdCode>";
// invoke the web service
showCall('generateAdCode', $param);
$response = $client->call('generateAdCode', $param, $namespace);
if ($client->fault) {
showMyErrors($client);
return;
}
$err = $client->getError();
if ($err) {
showSoapClientError($err);
return;
}
$response = $response['return'];
$snippet = $response;
showSnippet($snippet);
// showing the soap
showRequestResponse($client);
?>
Also, at the bottom of the results I get:
Fault Code
Fault: 1
Code: soapenv:Server.userException
String: org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.
Detail:
I tried all sorts of things, googled this error but I found no answers. If someone could take a look at this, it would be great!