Friday, June 17, 2011

This post confirms my ownership of the site

This post confirms my ownership of the site and that this site adheres to Google AdSense program policies and Terms and Conditions

Wednesday, June 15, 2011

Generate Ad Code using XML



INSERT_DEVELOPER_EMAIL_HERE
INSERT_PASSWORD_HERE
INSERT_PUBLISHER_CLIENT_ID_HERE



INSERT_PUBLISHER_SYNDICATION_SERVICE_ID_HERE

#FFFFFF
#000000

#00FF00
#0000CC
#FF3300


728x90

False

DEFAULT




source: http://code.google.com/p/adsense-api-xml-samples/source/browse/trunk/v3/generateAdCode.xml

Associate Account Using XML



INSERT_DEVELOPER_EMAIL_HERE
en_US
INSERT_PASSWORD_HERE



INSERT_PUBLISHER_EMAIL_HERE
12345

INSERT_DEVELOPER_URL_HERE



source: http://code.google.com/p/adsense-api-xml-samples/source/browse/trunk/v3/associateAccount.xml

Create Account Using XML



INSERT_DEVELOPER_EMAIL_HERE
en_US
INSERT_PASSWORD_HERE



INSERT_PUBLISHER_EMAIL_HERE

Individual

INSERT_PUBLISHER_URL_HERE
en
en_US
true

ContentAds

INSERT_DEVELOPER_URL_HERE



source: http://code.google.com/p/adsense-api-xml-samples/source/browse/trunk/v3/createAccount.xml

Generate Search Box Code Using C#

// Copyright 2010 Google Inc.
//
// 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.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AdSenseForSearchService;

namespace ASAPISampleCode
{
class GenerateSearchBoxCodeSample
{
static void Main(string[] args)
{
developer_email developerEmail = new developer_email();
developerEmail.Text = new string[] { "DEVELOPER_EMAIL" };
developer_password developerPassword = new developer_password();
developerPassword.Text = new string[] { "DEVELOPER_PASSWORD" };
client_id clientId = new client_id();
clientId.Text = new string[] { "PUBLISHER_CLIENT_ID" };

String synServiceId = "PUBLISHER_SYNDICATION_SERVICE_ID";
String country = "US";
SearchType searchType = new SearchType();
searchType.value = "GoogleSearch";
SiteProperties siteProperties = new SiteProperties();
siteProperties.encoding = "";
siteProperties.locale = "en";
SearchOptions searchOptions = new SearchOptions();
searchOptions.isSafeSearch = false;
searchOptions.showResultsInNewWindow = false;
// .net won't serialize the domains parameter if it's null
// an array containing only the empty string is our next best bet.
String[] domains = new String[] { "" };
String selectedDomain = null;
SearchBoxStyle searchBoxStyle = new SearchBoxStyle();
searchBoxStyle.backgroundColor = "#FFFFFF";
searchBoxStyle.isButtonBelow = true;
searchBoxStyle.isCustomStyle = false;
searchBoxStyle.isLogoAbove = true;
searchBoxStyle.searchStyleName = "Green Dream";
searchBoxStyle.textBoxLength = 30;
searchBoxStyle.textColor = "#000000";
LogoType logoType = new LogoType();
searchBoxStyle.logoType = new LogoType();
searchBoxStyle.logoType.value = "GoogleLogo";
String channelName = null;

generateSearchBoxCode request = new generateSearchBoxCode();
request.synServiceId = synServiceId;
request.country = country;
request.searchType = searchType;
request.siteProperties = siteProperties;
request.searchOptions = searchOptions;
request.domains = domains;
request.selectedDomain = selectedDomain;
request.searchBoxStyle = searchBoxStyle;
request.channelName = channelName;

v3AdSenseForSearchService service = new v3AdSenseForSearchService();
service.developer_emailValue = developerEmail;
service.developer_passwordValue = developerPassword;
service.client_idValue = clientId;

generateSearchBoxCodeResponse response = service.generateSearchBoxCode(request);
Console.WriteLine("Ad Code:\n{0}", response.@return);
}
}
}

source: http://code.google.com/p/adsense-api-csharp-samples/source/browse/trunk/src/v3/GenerateSearchBoxCodeSample.cs

Generate Ad Code using C#

// Copyright 2010 Google Inc.
//
// 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.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AdSenseForContentService;

namespace ASAPISampleCode
{
class GenerateAdCodeSample
{
static void Main(string[] args)
{
developer_email developerEmail = new developer_email();
developerEmail.Text = new string[] { "DEVELOPER_EMAIL" };
developer_password developerPassword = new developer_password();
developerPassword.Text = new string[] { "DEVELOPER_PASSWORD" };
client_id clientId = new client_id();
clientId.Text = new string[] { "PUBLISHER_CLIENT_ID" };

String synServiceId = "PUBLISHER_SYNDICATION_SERVICE_ID";
AdStyle adStyle = new AdStyle();
adStyle.backgroundColor = "#000000";
adStyle.borderColor = "#000000";
adStyle.name = null;
adStyle.textColor = "#FFFFFF";
adStyle.titleColor = "#FFFFFF";
adStyle.urlColor = "#FFFFFF";
AdUnitType adUnitType = new AdUnitType();
adUnitType.value = "TextOnly";
AdLayout layout = new AdLayout();
layout.value = "728x90";
String alternate = null;
bool isFramedPage = false;
String channelName = null;
CornerStyles cornerStyles = new CornerStyles();
cornerStyles.value = "DEFAULT";
string[] hostChannelNames = null;

generateAdCode request = new generateAdCode();
request.synServiceId = synServiceId;
request.adStyle = adStyle;
request.adUnitType = adUnitType;
request.adLayout = layout;
request.alternate = alternate;
request.isFramedPage = isFramedPage;
request.channelName = channelName;
request.cornerStyles = cornerStyles;
request.hostChannelNames = hostChannelNames;

v3AdSenseForContentService service = new v3AdSenseForContentService();
service.developer_emailValue = developerEmail;
service.developer_passwordValue = developerPassword;
service.client_idValue = clientId;

generateAdCodeResponse response = service.generateAdCode(request);
Console.WriteLine("Ad Code:\n{0}", response.@return);
}
}
}

source: http://code.google.com/p/adsense-api-csharp-samples/source/browse/trunk/src/v3/GenerateAdCodeSample.cs

Associate Account using C#

// Copyright 2010 Google Inc.
//
// 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.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AccountService;

namespace ASAPISampleCode
{
class AssociateAccountSample
{
static void Main(string[] args)
{
developer_email developerEmail = new developer_email();
developerEmail.Text = new string[] { "DEVELOPER_EMAIL" };
developer_password developerPassword = new developer_password();
developerPassword.Text = new string[] { "DEVELOPER_PASSWORD" };

String loginEmail = "USER_EMAIL";
String postalCode = "USER_POSTAL_CODE";
String phone = "USER_PHONE_NUMBER_LAST_FIVE_DIGITS";
String developerUrl = "DEVELOPER_URL";

associateAccount request = new associateAccount();
request.loginEmail = loginEmail;
request.postalCode = postalCode;
request.phone = phone;
request.developerUrl = developerUrl;

v3AccountService service = new v3AccountService();
service.developer_emailValue = developerEmail;
service.developer_passwordValue = developerPassword;

SyndicationService_Data[] response = service.associateAccount(request);
foreach (SyndicationService_Data data in response)
{
Console.WriteLine("Type: {0} Id: {1}", data.type.value, data.id);
}
}
}
}

source: http://code.google.com/p/adsense-api-csharp-samples/source/browse/trunk/src/v3/AssociateAccountSample.cs

Creaing Account Using C#

// Copyright 2010 Google Inc.
//
// 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.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AccountService;

namespace ASAPISampleCode
{
class CreateAccountSample
{
static void Main(string[] args)
{
developer_email developerEmail = new developer_email();
developerEmail.Text = new string[] { "DEVELOPER_EMAIL" };
developer_password developerPassword = new developer_password();
developerPassword.Text = new string[] { "DEVELOPER_PASSWORD" };

String loginEmail = "USER_EMAIL";
EntityType entityType = new EntityType();
entityType.value = "Individual";
String websiteUrl = "USERS_PRIMARY_WEBSITE_URL";
String websiteLocale = "en";
String usersPreferredLocale = "en_US";
bool emailPromotionsPreferences = false;
SyndicationService_Type[] synServiceTypes = new SyndicationService_Type[] { new SyndicationService_Type() };
synServiceTypes[0].value = "ContentAds";
String developerUrl = "DEVELOPER_URL";
createAccount data = new createAccount();
data.loginEmail = loginEmail;
data.entityType = entityType;
data.websiteUrl = websiteUrl;
data.websiteLocale = websiteLocale;
data.usersPreferredLocale = usersPreferredLocale;
data.emailPromotionsPreference = emailPromotionsPreferences;
data.synServiceTypes = synServiceTypes;
data.developerUrl = developerUrl;

v3AccountService service = new v3AccountService();
service.developer_emailValue = developerEmail;
service.developer_passwordValue = developerPassword;
SyndicationService_Data[] response = service.createAccount(data);
Console.WriteLine("Type: {0}, Id: {1}", response[0].type.value, response[0].id);
}
}
}

source: http://code.google.com/p/adsense-api-csharp-samples/source/browse/trunk/src/v3/CreateAccountSample.cs

Generate Ad Code using PHP

REPLACE WITH DEVELOPER EMAIL";
$password = "REPLACE WITH DEVELOPER PASSWORD";
$client_id = "REPLACE WITH 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 = "ContentAds";

// 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 .= "demoStyle";
$ads_param .= '#0000FF';
$ads_param .= '#FFFFFF';
$ads_param .= '#FF0000';
$ads_param .= '#00FF00';
$ads_param .= '#FFFF00';
$ads_param .= '
';

// setting up parameter
$param = ''.$synServiceId.'';
$param .= $ads_param;
$param .= 'TextOnly';
$param .= '728x90';
$param .= '#FFFFFF';
$param .= 'false';
$param .= '';
$param .= 'DEFAULT';

$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

Associate Account using PHP

REPLACE WITH DEVELOPER EMAIL";
$password = "REPLACE WITH DEVELOPER PASSWORD";
$client_id = "NOT RELEVANT";

$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 = "users_address_here@example.com";
$param .= "USERS POSTAL CODE";
$param .= "USERS PHONE NUMBER";
$param .= "SITE TO BE ASSOCIATED WITH THIS PUBLISHER";
$param = "" . $param . "";

// invoke web service
showCall('associateAccount', $param);
$response = $client->call('associateAccount', $param, $namespace);
if ($client->fault) {
showMyErrors($client);
return;
}
$err = $client->getError();
if ($err) {
showSoapClientError($err);
return;
}

// get back the response
$response = $response['return'];
showCreatedPublisher($response);

// showing the soap
showRequestResponse($client);

?>

source: http://code.google.com/p/google-sensapility/source/browse/trunk/samplecode/v3/AssociateAccount.php

Create Account using PHP

REPLACE WITH DEVELOPER EMAIL";
$password = "REPLACE WITH DEVELOPER PASSWORD";
$client_id = "NOT RELEVANT";

$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 parameters
$param = "users_address_here@example.com";
$param .= "Individual";
$param .= "http://test.aaa.com";
$param .= "en";
$param .= "en_US";
$param .= "true";
$param .= "ContentAds";
$param .= "code.google.com";
$param = "" . $param . "";

// invoke web service
showCall('createAccount', $param);
$response = $client->call('createAccount', $param, $namespace);
if ($client->fault) {
showMyErrors($client);
return;
}
$err = $client->getError();
if ($err) {
showSoapClientError($err);
return;
}

// get back the response
$response = $response['return'];
showCreatedPublisher($response);

// showing the soap
showRequestResponse($client);

?>

source: http://code.google.com/p/google-sensapility/source/browse/trunk/samplecode/v3/CreateAccount.php

Generate Ad Code using python

#!/usr/bin/python2.2
#
# Copyright 2006, Google Inc. All Rights Reserved.

#####################################################################
# Sample code to add a generate ad code snippet through Adsense API #
#####################################################################

import SOAPpy

server = "https://sandbox.google.com"

dev_email = "REPLACE WITH DEVELOPER EMAIL"
dev_password = "REPLACE WITH DEVELOPER PASSWORD"
client_id = "REPLACE WITH CLIENT ID"

# Set headers
headers = SOAPpy.Types.headerType()
headers.developer_email = dev_email
headers.developer_password = dev_password
headers.client_id = client_id

# Set service connection
service = SOAPpy.SOAPProxy(
server + "/api/adsense/v3/AccountService",
namespace="http://www.google.com/api/adsense/v3",
header=headers)
# To view xml request/response set service.config.debug = 1
service.config.debug = 0

syn_service_type = SOAPpy.Types.structType(name="synServiceTypes")
syn_service_type._addItem(name="value",value="ContentAds")

# Get the Syndication ID
# Might throw a soap exception on user input or error upon trying to connect
response = service.getSyndicationService(syn_service_type)
syn_id = response["id"]
print "syn id :", syn_id
print

# Set another service connetion
service = SOAPpy.SOAPProxy(
server + "/api/adsense/v3/AdSenseForContentService",
namespace="http://www.google.com/api/adsense/v3",
header=headers)
service.config.debug = 0

# Set up the ad style
ad_style_template = """
%s
%s
%s
%s
%s
%s
"""

ad_style = ad_style_template % ('#FFFFFF', '#0000FF', 'demoStyle',
'#00FF00', '#FF0000', '#FFFF00')
ad_style = SOAPpy.Types.untypedType(name="adStyle",data=ad_style)
#ad_style._setAttr(
# 'xmlns:impl',
# 'http://www.google.com/api/adsense/v3')
#ad_style._setAttr('xsi:type', 'impl:AdStyle')

# Set up other parameters
syn_service_id = SOAPpy.Types.untypedType(name="synServiceId",data=syn_id)
ad_unit_type = SOAPpy.Types.structType(name="adUnitType")
ad_unit_type._addItem(name="value",value="TextOnly")
layout = SOAPpy.Types.structType(name="adLayout")
layout._addItem(name="value",value="728x90")
alternate = SOAPpy.Types.untypedType(name="alternate",data="#FFFFFF")
is_framed_page = SOAPpy.Types.untypedType(name="isFramedPage",data="False")
channel_name = SOAPpy.Types.untypedType(name="channelName",data="")
corner_styles = SOAPpy.Types.structType(name="cornerStyles")
corner_styles._addItem(name="value",value="DEFAULT")

# Generate ad code, might throw a soap exception
# on user input or error upon trying to connect
response = service.generateAdCode(syn_service_id, ad_style, ad_unit_type,
layout, alternate, is_framed_page,
channel_name,corner_styles)

print "Ad code snippet :"
print response

source: http://code.google.com/p/adsense-api-python/source/browse/trunk/v3/samplecode/GenerateAdCodeSnippet.py

Associate Account using Python

#!/usr/bin/python2.2
#
# Copyright 2006, Google Inc. All Rights Reserved.

###################################################################
# sample code to associate an Adsense account through Adsense API #
###################################################################

import SOAPpy

server = "https://sandbox.google.com"

dev_email = "REPLACE WITH DEVELOPER EMAIL"
dev_password = "REPLACE WITH DEVELOPER PASSWORD"

# Set headers
headers = SOAPpy.Types.headerType()
headers.developer_email = dev_email
headers.developer_password = dev_password
headers.client_id = "will be ignored"


# Set service connection
service = SOAPpy.SOAPProxy(
server + "/api/adsense/v3/AccountService",
namespace="http://www.google.com/api/adsense/v3",
header=headers)
# To view xml request/response set service.config.debug = 1
service.config.debug = 0

# Set the parameters
login_email = SOAPpy.Types.untypedType(name="loginEmail",
data="user_address_here@example.com")
postal_code = SOAPpy.Types.untypedType(name="postalCode",data="")
phone = SOAPpy.Types.untypedType(name="phone",data="")
developer_url = SOAPpy.Types.untypedType(name="developerUrl",
data="code.google.com")

try:
response = service.associateAccount(
login_email,
postal_code,
phone,
developer_url
)
except SOAPpy.Types.faultType, fault:
print "Fault!"
print " trigger :",fault['detail']['AdSenseApiExceptionFault']['AdSenseApiException']['trigger']
print " message :",fault['detail']['AdSenseApiExceptionFault']['AdSenseApiException']['message']
print " code :",fault['detail']['AdSenseApiExceptionFault']['AdSenseApiException']['code']
exit(1)

# Print results
print "Adsense account association successful"
if type(response)==list:
for i in response:
print "account type :",i['type']['value']
print " syn id :",i['id']
else:
print "account type :",response['type']['value']
print " syn id :",response['id']

source: http://code.google.com/p/adsense-api-python/source/browse/trunk/v3/samplecode/AssociateAccount.py

Create Account using Python

#!/usr/bin/python2.2
#
# Copyright 2006, Google Inc. All Rights Reserved.

################################################################
# sample code to create an Adsense account through Adsense API #
################################################################

import SOAPpy

server = "https://sandbox.google.com"

dev_email = "REPLACE WITH DEVELOPER EMAIL"
dev_password = "REPLACE WITH DEVELOPER PASSWORD"

# Set headers
headers = SOAPpy.Types.headerType()
headers.developer_email = dev_email
headers.developer_password = dev_password
headers.client_id = "will be ignored"


# Set service connection
service = SOAPpy.SOAPProxy(
server + "/api/adsense/v3/AccountService",
namespace="http://www.google.com/api/adsense/v3",
header=headers)
# To view xml request/response set service.config.debug = 1
service.config.debug = 0

# Set the parameters
login_email = SOAPpy.Types.untypedType(name="loginEmail",
data="user_address_here@example.com")
entity_type = SOAPpy.structType(name="entityType")
entity_type._addItem("value","Individual")
website_url = SOAPpy.Types.untypedType(name="websiteUrl",
data="http://test.aaa.com")
website_locale = SOAPpy.Types.untypedType(name="websiteLocale",
data="en")
users_preferred_locale = SOAPpy.Types.untypedType(name="usersPreferredLocale",
data="en_US")
email_promotion_preferences = SOAPpy.Types.untypedType(name="emailPromotionsPreference",
data="true")
syn_service_types0 = SOAPpy.structType(name="synServiceTypes")
syn_service_types0._addItem(name="value",value="ContentAds")
syn_service_types1 = SOAPpy.structType(name="synServiceTypes")
syn_service_types1._addItem(name="value",value="SearchAds")
developer_url = SOAPpy.Types.untypedType(name="developerUrl",
data="code.google.com")

# Create an adsense account, might throw a soap exception
# on user input or error upon trying to connect
try:
response = service.createAccount(
login_email,
entity_type,
website_url,
website_locale,
users_preferred_locale,
email_promotion_preferences,
syn_service_types0,
syn_service_types1,
developer_url
)
except SOAPpy.Types.faultType, fault:
print "Fault!"
print " trigger :",fault['detail']['AdSenseApiExceptionFault']['AdSenseApiException']['trigger']
print " message :",fault['detail']['AdSenseApiExceptionFault']['AdSenseApiException']['message']
print " code :",fault['detail']['AdSenseApiExceptionFault']['AdSenseApiException']['code']
exit(1)

# Print results
print "Adsense account creation successful"
if type(response)==list:
for i in response:
print "account type :",i['type']['value']
print " syn id :",i['id']
else:
print "account type :",response['type']['value']
print " syn id :",response['id']

source: http://code.google.com/p/adsense-api-python/source/browse/trunk/v3/samplecode/CreateAccount.py

Generate Ad Code using Java

// Copyright 2009 Google Inc.
//
// 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.

package v3;

import com.google.api.adsense.v3.AdSenseForContentService.GenerateAdCodeFault;
import com.google.api.adsense.v3.AdSenseForContentService.V3AdSenseForContentServicev3AdSenseForContentServiceSOAP11Port_httpsStub;

import org.apache.axis2.client.ServiceClient;
import org.apache.axiom.om.OMElement;

import java.util.Iterator;
import javax.xml.namespace.QName;

/**
* Sample code for calling AdSense API v3's AssociateAccount method.
*
* @author api.wes@gmail.com (Wes Goodman)
*/
public class GenerateAdCode {
static final String _DEVELOPER_EMAIL = "DEVELOPER_EMAIL";
static final String _DEVELOPER_PASS = "DEVELOPER_PASSWORD";
static final String _ADSENSE_V3_NS = "http://www.google.com/api/adsense/v3";

/**
* @param args
*/
public static void main(String[] args) {
try {
V3AdSenseForContentServicev3AdSenseForContentServiceSOAP11Port_httpsStub afc_service =
new V3AdSenseForContentServicev3AdSenseForContentServiceSOAP11Port_httpsStub();
ServiceClient service_client = afc_service._getServiceClient();
service_client.addStringHeader(new QName(_ADSENSE_V3_NS,
"developer_email"),
_DEVELOPER_EMAIL);
service_client.addStringHeader(new QName(_ADSENSE_V3_NS,
"developer_password"),
_DEVELOPER_PASS);
service_client.addStringHeader(new QName(_ADSENSE_V3_NS,
"client_id"),
"PUBLISHER CLIENT ID");

V3AdSenseForContentServicev3AdSenseForContentServiceSOAP11Port_httpsStub.GenerateAdCode generate_msg =
new V3AdSenseForContentServicev3AdSenseForContentServiceSOAP11Port_httpsStub.GenerateAdCode();
generate_msg.setSynServiceId("PUBLISHER SYNDICATION SERVICE ID");

V3AdSenseForContentServicev3AdSenseForContentServiceSOAP11Port_httpsStub.AdStyle ad_style =
new V3AdSenseForContentServicev3AdSenseForContentServiceSOAP11Port_httpsStub.AdStyle();
ad_style.setBackgroundColor("#000000");
ad_style.setBorderColor("#000000");
ad_style.setName("temp name");
ad_style.setTextColor("#FFFFFF");
ad_style.setTitleColor("FFFFFF");
ad_style.setUrlColor("#FFFFFF");
generate_msg.setAdStyle(ad_style);

V3AdSenseForContentServicev3AdSenseForContentServiceSOAP11Port_httpsStub.AdUnitType ad_unit_type =
new V3AdSenseForContentServicev3AdSenseForContentServiceSOAP11Port_httpsStub.AdUnitType();
ad_unit_type.setValue("TextOnly");
generate_msg.setAdUnitType(ad_unit_type);

V3AdSenseForContentServicev3AdSenseForContentServiceSOAP11Port_httpsStub.AdLayout ad_layout =
new V3AdSenseForContentServicev3AdSenseForContentServiceSOAP11Port_httpsStub.AdLayout();
ad_layout.setValue("728x90");
generate_msg.setAdLayout(ad_layout);

generate_msg.setAlternate(null);
generate_msg.setIsFramedPage(false);
generate_msg.setChannelName(null);

V3AdSenseForContentServicev3AdSenseForContentServiceSOAP11Port_httpsStub.CornerStyles corner_styles =
new V3AdSenseForContentServicev3AdSenseForContentServiceSOAP11Port_httpsStub.CornerStyles();
corner_styles.setValue("DEFAULT");
generate_msg.setCornerStyles(corner_styles);

generate_msg.setHostChannelNames(null);

V3AdSenseForContentServicev3AdSenseForContentServiceSOAP11Port_httpsStub.GenerateAdCodeResponse response =
afc_service.generateAdCode(generate_msg);

System.out.println("AdCode:");
System.out.println(response.get_return());

} catch (GenerateAdCodeFault fault) {
System.out.println("Due to axis issues, only AxisFault will ever be thrown");
System.out.println("Therefore, this catch block is for completeness only.");
} catch (org.apache.axis2.AxisFault fault) {
OMElement faultElement = fault.getDetail();
OMElement exElement = (OMElement) (faultElement.getChildElements().next());
Iterator i = exElement.getChildElements();
OMElement codeElement = (OMElement) i.next();
OMElement internalElement = (OMElement) i.next();
OMElement messageElement = (OMElement) i.next();
OMElement triggerElement = (OMElement) i.next();
OMElement triggerDetailsElement = (OMElement) i.next();
System.out.println("Code: " + codeElement.getText());
System.out.println("Internal: " + internalElement.getText());
System.out.println("Message: " + messageElement.getText());
System.out.println("Trigger: " + triggerElement.getText());
System.out.println("Trigger Detail: " + triggerDetailsElement.getText());
} catch (java.rmi.RemoteException e) {
System.out.println("remote exception");
}
}
}

source: http://code.google.com/p/adsense-api-java-samples/source/browse/trunk/src/v3/GenerateAdCode.java

Assosciate Account using Java

// Copyright 2009 Google Inc.
//
// 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.

package v3;

import com.google.api.adsense.v3.AccountService.AssociateAccountFault;
import com.google.api.adsense.v3.AccountService.V3AccountServicev3AccountServiceSOAP11Port_httpsStub;
import com.google.api.adsense.v3.AccountService.V3AccountServicev3AccountServiceSOAP11Port_httpsStub.SyndicationService_Data;

import org.apache.axis2.client.ServiceClient;
import org.apache.axiom.om.OMElement;

import java.util.Iterator;
import javax.xml.namespace.QName;

/**
* Sample code for calling AdSense API v3's AssociateAccount method.
*
* @author api.wes@gmail.com (Wes Goodman)
*/
public class AssociateAccount {
static final String _DEVELOPER_EMAIL = "DEVELOPER_EMAIL";
static final String _DEVELOPER_PASS = "DEVELOPER_PASSWORD";
static final String _ADSENSE_V3_NS = "http://www.google.com/api/adsense/v3";

/**
* @param args
*/
public static void main(String[] args) {
try {
V3AccountServicev3AccountServiceSOAP11Port_httpsStub account_service =
new V3AccountServicev3AccountServiceSOAP11Port_httpsStub();
ServiceClient service_client = account_service._getServiceClient();
service_client.addStringHeader(new QName(_ADSENSE_V3_NS,
"developer_email"),
_DEVELOPER_EMAIL);
service_client.addStringHeader(new QName(_ADSENSE_V3_NS,
"developer_password"),
_DEVELOPER_PASS);

V3AccountServicev3AccountServiceSOAP11Port_httpsStub.AssociateAccount associate_msg =
new V3AccountServicev3AccountServiceSOAP11Port_httpsStub.AssociateAccount();
associate_msg.setLoginEmail("USER_EMAIL");
// Either-or for PostalCode and Phone, though the service will work if both are set.
associate_msg.setPostalCode("USER_POSTAL_CODE");
associate_msg.setPhone("USER_PHONE_NUMBER_LAST_FIVE_DIGITS");
associate_msg.setDeveloperUrl("DEVELOPER_URL");

V3AccountServicev3AccountServiceSOAP11Port_httpsStub.AssociateAccountResponse response =
account_service.associateAccount(associate_msg);

V3AccountServicev3AccountServiceSOAP11Port_httpsStub.SyndicationService_Data[] synservice_response =
response.get_return();
for (SyndicationService_Data syndicationService_Data : synservice_response) {
System.out.println("Syndication Type: " + syndicationService_Data.getType().getValue());
System.out.println("Publisher Id: " + syndicationService_Data.getId());
}
} catch (AssociateAccountFault fault) {
System.out.println("Due to axis issues, only AxisFault will ever be thrown");
System.out.println("Therefore, this catch block is for completeness only.");
} catch (org.apache.axis2.AxisFault fault) {
OMElement faultElement = fault.getDetail();
OMElement exElement = (OMElement) (faultElement.getChildElements().next());
Iterator i = exElement.getChildElements();
OMElement codeElement = (OMElement) i.next();
OMElement internalElement = (OMElement) i.next();
OMElement messageElement = (OMElement) i.next();
OMElement triggerElement = (OMElement) i.next();
OMElement triggerDetailsElement = (OMElement) i.next();
System.out.println("Code: " + codeElement.getText());
System.out.println("Internal: " + internalElement.getText());
System.out.println("Message: " + messageElement.getText());
System.out.println("Trigger: " + triggerElement.getText());
System.out.println("Trigger Detail: " + triggerDetailsElement.getText());
} catch (java.rmi.RemoteException e) {
System.out.println("remote exception");
}
}
}

source: http://code.google.com/p/adsense-api-java-samples/source/browse/trunk/src/v3/AssociateAccount.java

Create Account using Java

// Copyright 2009 Google Inc.
//
// 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.

package v3;

import com.google.api.adsense.v3.AccountService.CreateAccountFault;
import com.google.api.adsense.v3.AccountService.V3AccountServicev3AccountServiceSOAP11Port_httpsStub;
import com.google.api.adsense.v3.AccountService.V3AccountServicev3AccountServiceSOAP11Port_httpsStub.SyndicationService_Data;

import org.apache.axis2.client.ServiceClient;
import org.apache.axiom.om.OMElement;

import java.util.Iterator;
import javax.xml.namespace.QName;

/**
* Sample code for calling AdSense API v3's CreateAccount method.
*
* @author api.wes@gmail.com (Wes Goodman)
*/
public class CreateAccount {
static final String _DEVELOPER_EMAIL = "DEVELOPER_EMAIL";
static final String _DEVELOPER_PASS = "DEVELOPER_PASSWORD";
static final String _ADSENSE_V3_NS = "http://www.google.com/api/adsense/v3";

/**
* @param args
*/
public static void main(String[] args) {
try {
V3AccountServicev3AccountServiceSOAP11Port_httpsStub account_service =
new V3AccountServicev3AccountServiceSOAP11Port_httpsStub();
ServiceClient service_client = account_service._getServiceClient();
service_client.addStringHeader(new QName(_ADSENSE_V3_NS,
"developer_email"),
_DEVELOPER_EMAIL);
service_client.addStringHeader(new QName(_ADSENSE_V3_NS,
"developer_password"),
_DEVELOPER_PASS);

V3AccountServicev3AccountServiceSOAP11Port_httpsStub.CreateAccount account_msg =
new V3AccountServicev3AccountServiceSOAP11Port_httpsStub.CreateAccount();
account_msg.setLoginEmail("USER_EMAIL");

V3AccountServicev3AccountServiceSOAP11Port_httpsStub.EntityType entity_type =
new V3AccountServicev3AccountServiceSOAP11Port_httpsStub.EntityType();
entity_type.setValue("Individual");
account_msg.setEntityType(entity_type);

account_msg.setWebsiteUrl("USERS_PRIMARY_WEBSITE_URL");
account_msg.setWebsiteLocale("en");
account_msg.setUsersPreferredLocale("en_US");
account_msg.setEmailPromotionsPreference(false);

V3AccountServicev3AccountServiceSOAP11Port_httpsStub.SyndicationService_Type synservice_type =
new V3AccountServicev3AccountServiceSOAP11Port_httpsStub.SyndicationService_Type();
synservice_type.setValue("ContentAds");
account_msg.addSynServiceTypes(synservice_type);

account_msg.setDeveloperUrl("DEVELOPER_URL");

V3AccountServicev3AccountServiceSOAP11Port_httpsStub.CreateAccountResponse response =
account_service.createAccount(account_msg);

V3AccountServicev3AccountServiceSOAP11Port_httpsStub.SyndicationService_Data[] synservice_response =
response.get_return();
for (SyndicationService_Data syndicationService_Data : synservice_response) {
System.out.println("Syndication Type: " + syndicationService_Data.getType().getValue());
System.out.println("Publisher Id: " + syndicationService_Data.getId());
}
} catch (CreateAccountFault fault) {
System.out.println("Due to axis issues, only AxisFault will ever be thrown");
System.out.println("Therefore, this catch block is for completeness only.");
} catch (org.apache.axis2.AxisFault fault) {
OMElement faultElement = fault.getDetail();
OMElement exElement = (OMElement) (faultElement.getChildElements().next());
Iterator i = exElement.getChildElements();
OMElement codeElement = (OMElement) i.next();
OMElement internalElement = (OMElement) i.next();
OMElement messageElement = (OMElement) i.next();
OMElement triggerElement = (OMElement) i.next();
OMElement triggerDetailsElement = (OMElement) i.next();
System.out.println("Code: " + codeElement.getText());
System.out.println("Internal: " + internalElement.getText());
System.out.println("Message: " + messageElement.getText());
System.out.println("Trigger: " + triggerElement.getText());
System.out.println("Trigger Detail: " + triggerDetailsElement.getText());
} catch (java.rmi.RemoteException e) {
System.out.println("remote exception");
}
}
}

source: http://code.google.com/p/adsense-api-java-samples/source/browse/trunk/src/v3/CreateAccount.java