#!/usr/bin/python2.2 # # Copyright 2006, Google Inc. All Rights Reserved. ################################################################### # Sample code to generate search code snippet 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 = "partner-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("SearchAds") # 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 AdSenseForSearchService connection. service = SOAPpy.SOAPProxy( server + "/api/adsense/v2/AdSenseForSearchService", header=headers) service.config.debug = 0 # Set the search options. search_options_template = """ %s %s""" search_options = search_options_template % ('true', 'false') search_options = SOAPpy.Types.untypedType(search_options) search_options._setAttr( 'xmlns:impl', 'http://www.google.com/api/adsense/v2') search_options._setAttr('xsi:type', 'impl:SearchOptions') # Set the site properties. site_properties_template = """ %s %s""" site_properties = site_properties_template % ('', 'en') site_properties = SOAPpy.Types.untypedType(site_properties) site_properties._setAttr( 'xmlns:impl', 'http://www.google.com/api/adsense/v2') site_properties._setAttr('xsi:type', 'impl:SiteProperties') # Set the search box style. style_template = """ %s %s %s %s %s %s %s %s""" style = style_template % ('#CCCCCC', 'false', 'false', 'false', 'GoogleLogo', 'Blue Sky', '62', 'black') style = SOAPpy.Types.untypedType(style) style._setAttr( 'xmlns:impl', 'http://www.google.com/api/adsense/v2') style._setAttr('xsi:type', 'impl:SearchBoxStyle') # Set up other parameters syn_service_id = SOAPpy.Types.untypedType(syn_id) country = SOAPpy.Types.untypedType('US') searchType = SOAPpy.Types.untypedType('GoogleSiteSearch') domains = SOAPpy.Types.arrayType(['test1.com', 'test2.com']) selectedDomain = SOAPpy.Types.untypedType('') channelName = SOAPpy.Types.untypedType('') # Generate and print the code. response = service.generateSearchBoxCode(syn_service_id, country, searchType, site_properties, search_options, domains, selectedDomain, style, channelName) print "Search code snippet :" print response