Google AdSense API
Google has just opened for all developers their AdSense API introduced last year:
If you're a web developer or host, you may remember that we introduced you to the AdSense API last May. With the AdSense API, your users can create their own AdSense accounts on your site, and display ads alongside the content that they have created. They can also manage their accounts and view ad performance and earnings reports, all on your site.
…
Today, we're pleased to announce that the AdSense API is now open for all developers, with the release of our open development sandbox. This is a replica of the live service with some additional support to help you test and debug your applications. Once you implement the AdSense API in the development sandbox, we can go live with your implementation.
Using this API you can share advertising revenues with creating content online users without webnasters worrying too much about accounting and money, all managed by Google. It looks liek a win-win situation for everybody.
Some already fear that AdSense API will skyrocket click-fraud. However this is a sample account creatin using PHP straight from their online documentation:
<?php
// Copyright 2005, Google Inc. All rights reserved.
/**
* sample code to create an Adsense account through Adsense API
*/
require_once('lib/nusoap.php');
require_once('common.php');
$server = 'https://www.google.com';
$namespace = 'http://www.google.com/api/adsense/v2';
// Set up the authentication headers
$email = '<impl:developer_email>REPLACE WITH DEVELOPER EMAIL</impl:developer_email>';
$password = '<impl:developer_password>REPLACE WITH DEVELOPER PASSWORD</impl:developer_password>';
$client_id = '<impl:client_id>NOT RELEVANT</impl:client_id>';
$header = $email . $password . $client_id;
// creating soap client
$wsdl = $server . '/api/adsense/v2/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 = '<loginEmail>users_address_here@example.com</loginEmail>';
$param .= '<entityType>Individual</entityType>';
$param .= '<websiteUrl>http://test.aaa.com</websiteUrl>';
$param .= '<websiteLocale>en</websiteLocale>';
$param .= '<usersPreferredLocale>en_US</usersPreferredLocale>';
$param .= '<emailPromotionPreferences>true</emailPromotionPreferences>';
$param .= '<synServiceTypes>ContentAds</synServiceTypes>';
$param .= '<hasAcceptedTCs>true</hasAcceptedTCs>';
$param = '<createAdSenseAccount>' . $param . '</createAdSenseAccount>';
// invoke web service
showCall('createAdSenseAccount', $param);
$response = $client->call('createAdSenseAccount', $param, $namespace);
if ($client->fault) {
showMyErrors($client);
return;
}
$err = $client->getError();
if ($err) {
showSoapClientError($err);
return;
}
// get back the response
$response = $response['createAdSenseAccountReturn'];
showCreatedPublisher($response);
// showing the soap
showRequestResponse($client);
?>