// Copyright 2005 Google Inc. All rights reserved. using System; /** * Sample code to generate ad code snippet of an existing account * through Adsense API */ namespace AdSenseApi { public class GenerateAdCodeSnippet { public static void MainGenerateAdCodeSnippet() { 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 serverAFCService.AdSenseForContentServiceService afcService = new serverAFCService.AdSenseForContentServiceService(); // set the headers afcService.developer_emailValue = new serverAFCService.developer_email(); afcService.developer_emailValue.Text = new string[] { developerEmail }; afcService.developer_passwordValue = new serverAFCService.developer_password(); afcService.developer_passwordValue.Text = new string[] { developerPassword }; afcService.client_idValue = new serverAFCService.client_id(); afcService.client_idValue.Text = new string[] { clientId }; // set the parameters serverAFCService.AdStyle adStyle = new serverAFCService.AdStyle(); adStyle.name = "demoStyle"; adStyle.borderColor = "#0000FF"; adStyle.backgroundColor = "#FFFFFF"; adStyle.titleColor = "#FF0000"; adStyle.textColor = "#00FF00"; adStyle.urlColor = "#FFFF00"; // get the code snippet string snippet = afcService.generateAdCode( synServiceId, adStyle, "TextOnly", "728x90", "#FFFFFF", false, null ); // displays the result Console.WriteLine("Generating ad code successful"); Console.WriteLine("ad snippet : "); Console.WriteLine("{0}", snippet); } catch (System.Web.Services.Protocols.SoapException e) { // displays errors Console.WriteLine("Generating ad code failed"); Console.WriteLine("message : {0}", e.Message); Console.WriteLine("source : {0}", e.Source); Console.WriteLine("stacktrace : {0}", e.StackTrace); } } } }