using System; using System.Net; using System.Web; using System.Xml; /** * Sample code to generate search code snippet through Adsense API */ namespace AdSenseApi { public class GenerateSearchCodeSnippet { public static void MainGenerateSearchCodeSnippet() { try { // initialize service serverAFSService.AdSenseForSearchServiceService service = new serverAFSService.AdSenseForSearchServiceService(); // set the headers string developerEmail = "REPLACE WITH DEVELOPER'S EMAIL"; string developerPassword = "REPLACE WITH DEVELOPER'S PASSWORD"; string clientId = "partner-pub-REPLACE WITH CLIENT'S ID"; service.developer_emailValue = new serverAFSService.developer_email(); service.developer_emailValue.Text = new string[] { developerEmail }; service.developer_passwordValue = new serverAFSService.developer_password(); service.developer_passwordValue.Text = new string[] { developerPassword }; service.client_idValue = new serverAFSService.client_id(); service.client_idValue.Text = new string[] { clientId }; serverAFSService.SearchOptions searchOptions = new serverAFSService.SearchOptions(); searchOptions.isSafeSearch = true; searchOptions.showResultsInNewWindow = false; serverAFSService.SiteProperties siteProperties = new serverAFSService.SiteProperties(); siteProperties.locale = "en"; siteProperties.encoding = ""; serverAFSService.SearchBoxStyle searchBoxStyle = new serverAFSService.SearchBoxStyle(); searchBoxStyle.logoType = "GoogleLogo"; searchBoxStyle.isLogoAbove = false; searchBoxStyle.isButtonBelow = false; searchBoxStyle.backgroundColor = "#CCCCCC"; searchBoxStyle.textColor = "black"; searchBoxStyle.textBoxLength = 62; searchBoxStyle.isCustomStyle = false; searchBoxStyle.searchStyleName = "Blue Sky"; string[] domains = {"test1.com", "test2.com"}; // generate the search code string result = service.generateSearchBoxCode(clientId, "US", "GoogleSiteSearch", siteProperties, searchOptions, domains, "", searchBoxStyle, ""); // displays the result Console.WriteLine("Generating search code successful"); Console.WriteLine("search box snippet : "); Console.WriteLine("{0}", result); } catch (System.Web.Services.Protocols.SoapException e) { // displays errors Console.WriteLine("search code generation failed"); Console.WriteLine("message : {0}", e.Message); Console.WriteLine("source : {0}", e.Source); Console.WriteLine("stacktrace : {0}", e.StackTrace); } } } }