#!/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
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment