Google.Api.Ads.AdWords.Examples.CSharp.v201306.CreateAccount.Run C# (CSharp) Method

Run() public method

Runs the code example.
public Run ( Google.Api.Ads.AdWords.Lib.AdWordsUser user ) : void
user Google.Api.Ads.AdWords.Lib.AdWordsUser The AdWords user.
return void
        public void Run(AdWordsUser user)
        {
            // Get the ManagedCustomerService.
              ManagedCustomerService managedCustomerService = (ManagedCustomerService) user.GetService(
              AdWordsService.v201306.ManagedCustomerService);

              // Create account.
              ManagedCustomer customer = new ManagedCustomer();
              customer.name = "Customer created with ManagedCustomerService on " +
              new DateTime().ToString();
              customer.currencyCode = "EUR";
              customer.dateTimeZone = "Europe/London";

              // Create operations.
              ManagedCustomerOperation operation = new ManagedCustomerOperation();
              operation.operand = customer;
              operation.@operator = Operator.ADD;
              try {
            ManagedCustomerOperation[] operations = new ManagedCustomerOperation[] {operation};
            // Add account.
            ManagedCustomerReturnValue result = managedCustomerService.mutate(operations);

            // Display accounts.
            if (result.value != null && result.value.Length > 0) {
              ManagedCustomer customerResult = result.value[0];
              Console.WriteLine("Account with customer ID \"{0}\" was created.",
              customerResult.customerId);
            } else {
              Console.WriteLine("No accounts were created.");
            }
              } catch (Exception ex) {
            throw new System.ApplicationException("Failed to create accounts.", ex);
              }
        }

Usage Example

 /// <summary>
 /// Main method, to run this code example as a standalone application.
 /// </summary>
 /// <param name="args">The command line arguments.</param>
 public static void Main(string[] args)
 {
     CreateAccount codeExample = new CreateAccount();
       Console.WriteLine(codeExample.Description);
       try {
     codeExample.Run(new AdWordsUser());
       } catch (Exception ex) {
     Console.WriteLine("An exception occurred while running this code example. {0}",
     ExampleUtilities.FormatException(ex));
       }
 }
CreateAccount