// Copyright 2006 Google Inc. All rights reserved. using System; /** * Sample code to create a new channel using the * AccountService and ChannelService. */ namespace AdSenseApi { public class CreateChannel { public static void MainCreateChannel() { 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 = "ca-pub-REPLACE WITH CLIENT 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 serverChannelService.ChannelServiceService channelService = new serverChannelService.ChannelServiceService(); // set the headers channelService.developer_emailValue = new serverChannelService.developer_email(); channelService.developer_emailValue.Text = new string[] { developerEmail }; channelService.developer_passwordValue = new serverChannelService.developer_password(); channelService.developer_passwordValue.Text = new string[] { developerPassword }; channelService.client_idValue = new serverChannelService.client_id(); channelService.client_idValue.Text = new string[] { clientId }; // set the parameters serverChannelService.ChannelService_Data data = new serverChannelService.ChannelService_Data(); data.id = 0; // unused, but we set it anyway data.name = "http://www.example.com"; data.status = "Active"; data.type = "Url"; data.synServiceId = synServiceId; // Make the call to createChannel. serverChannelService.ChannelService_Data result = channelService.createChannel(data); // displays the result Console.WriteLine("Created a new {0} channel with ID {1} for {2}.", result.type, result.id, result.name); } catch (System.Web.Services.Protocols.SoapException e) { // displays errors Console.WriteLine("Channel creation failed."); Console.WriteLine("message : {0}", e.Message); Console.WriteLine("source : {0}", e.Source); Console.WriteLine("stacktrace : {0}", e.StackTrace); } } } }