// Copyright 2005 Google Inc. All rights reserved. using System; /** * Sample code to add a site filter to an existing Adsense account through * Adsense API */ namespace AdSenseApi { public class AddSiteFilter { public static void MainAddSiteFilter() { try { // initialize service serverAccountService.AccountServiceService accountService = new serverAccountService.AccountServiceService(); // set the headers string developerEmail = "REPLACE WITH DEVELOPER'S EMAIL"; string developerPassword = "REPLACE WITH DEVELOPER'S PASSWORD"; string clientId = "REPLACE WITH CLIENT'S ID"; accountService.developer_emailValue = new serverAccountService.developer_email(); accountService.developer_emailValue.Text = new string[] { developerEmail }; accountService.developer_passwordValue = new serverAccountService.developer_password(); accountService.developer_passwordValue.Text = new string[] { developerPassword }; accountService.client_idValue = new serverAccountService.client_id(); accountService.client_idValue.Text = new string[] { clientId }; // get the syndication ID string synServiceId = accountService.getSyndicationService("ContentAds").id; // initialize another service serverSiteFilterService.SiteFilterServiceService siteFilterService = new serverSiteFilterService.SiteFilterServiceService(); // set the headers siteFilterService.developer_emailValue = new serverSiteFilterService.developer_email(); siteFilterService.developer_emailValue.Text = new string[] {developerEmail}; siteFilterService.developer_passwordValue = new serverSiteFilterService.developer_password(); siteFilterService.developer_passwordValue.Text = new string[] {developerPassword}; siteFilterService.client_idValue = new serverSiteFilterService.client_id(); siteFilterService.client_idValue.Text = new string[] {clientId}; // adding site filter siteFilterService.addSiteFilters(synServiceId, new string[] {"www.example_filter.com"}); Console.WriteLine("Adding site filter successful"); } catch (System.Web.Services.Protocols.SoapException e) { // displays errors Console.WriteLine("Adding site filter failed"); Console.WriteLine("message : {0}", e.Message); Console.WriteLine("source : {0}", e.Source); Console.WriteLine("stacktrace : {0}", e.StackTrace); } } } }