// Copyright 2005, Google Inc. All rights reserved.
/**
* sample code to generate ad code snippet of an existing account through Adsense API
*/
require_once('lib/nusoap.php');
require_once('common.php');
$server = 'https://sandbox.google.com';
// Comment out the line above and uncomment the line below to use
// the production API server
// $server = 'https://www.google.com';
$namespace = 'http://www.google.com/api/adsense/v3';
// Set up the authentication headers
$email = "
$password = "
$client_id = "
$header = $email . $password . $client_id;
// creating soap client
$wsdl = $server . '/api/adsense/v3/AccountService?wsdl';
$client = new soapclient($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 the parameter
$param = "
// invoke web service
showCall('getSyndicationService', $param);
$response = $client->call('getSyndicationService', $param, $namespace);
if ($client->fault) {
showMyErrors($client);
return;
}
$err = $client->getError();
if ($err) {
showSoapClientError($err);
return;
}
// get back the response
$response = $response['return'];
$synServiceId = $response['id'];
showSynServiceId($synServiceId);
// showing the soap
showRequestResponse($client);
// setup client soap for another webservice
$wsdl = $server . '/api/adsense/v3/AdSenseForContentService?wsdl';
$client = new soapclient($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 = '
$ads_param .= "
$ads_param .= '
$ads_param .= '
$ads_param .= '
$ads_param .= '
$ads_param .= '
$ads_param .= '
// setting up parameter
$param = '
$param .= $ads_param;
$param .= '
$param .= '
$param .= '
$param .= '
$param .= '
$param .= '
$param = "
// 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);
?>
source: http://code.google.com/p/google-sensapility/source/browse/trunk/samplecode/v3/GenerateAdCode.php
No comments:
Post a Comment