#!/usr/bin/python2.2 # # Copyright 2006, Google Inc. All Rights Reserved. ################################################################### # Sample code to add a site filter to an existing Adsense account # # through Adsense API # ################################################################### import SOAPpy server = "https://www.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/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 another service connetion service = SOAPpy.SOAPProxy( server + "/api/adsense/v2/SiteFilterService", header=headers) service.config.debug = 0 # Set the parameters syn_service_id = SOAPpy.Types.untypedType(syn_id) site_filters = SOAPpy.Types.untypedType("www.example.com") # Add site filter, might throw a soap exception # on user input or error upon trying to connect response = service.addSiteFilters(syn_service_id, site_filters) print "Site filter is added succesfully"