#!/usr/bin/python2.2 # # Copyright 2006, Google Inc. All Rights Reserved. ############################################################### # Sample code to create a new URL channel through AdSense API # ############################################################### import SOAPpy server = "https://www.google.com" dev_email = "REPLACE WITH DEVELOPER'S EMAIL" dev_password = "REPLACE WITH DEVELOPER'S PASSWORD" client_id = "ca-pub-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 up the AccountService connection. service = SOAPpy.SOAPProxy( server + "/api/adsense/v2/AccountService", header=headers) # To view xml request/response set service.config.debug = 1 service.config.debug = 0 syn_service_type = SOAPpy.Types.untypedType("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 up the ChannelService connection. service = SOAPpy.SOAPProxy( server + "/api/adsense/v2/ChannelService", header=headers) service.config.debug = 0 # Set up the ChannelService_Data. channel_data_template = """ %s %s %s %s %s""" channel_data = channel_data_template % ('0', 'http://www.example.com', 'Active', syn_id, 'Url') channel_data = SOAPpy.Types.untypedType(channel_data) channel_data._setAttr( 'xmlns:impl', 'http://www.google.com/api/adsense/v2') channel_data._setAttr('xsi:type', 'impl:ChannelService_Data') # Create the channel. Might throw a SOAP exception # on user input or error upon trying to connect. response = service.createChannel(channel_data) print ("Created a new " + response['type'] + " channel with ID " + response['id'] + " for " + response['name'])