1 (user.Config as AdWordsAppConfig).ClientCustomerId = "442-017-1224";
2 // Get the ManagedCustomerService.
3 ManagedCustomerService managedCustomerService = (ManagedCustomerService)user.GetService(AdWordsService.v201409.ManagedCustomerService);
4 // Create selector.
5 Selector selector = new Selector();
6 selector.fields = new String[] { "CustomerId", "Name" };
7 try
8 {
9 ManagedCustomerPage page = managedCustomerService.get(selector);
10 if (page.entries != null)
11 {
12 // Create map from customerId to customer node.
13 //Dictionary<long, ManagedCustomerTreeNode> customerIdToCustomerNode =
14 //new Dictionary<long, ManagedCustomerTreeNode>();
15 // Create account tree nodes for each customer.
16 foreach (ManagedCustomer customer in page.entries)
17 {
dtClients.Rows.Add(customer.customerId.ToString(), customer.name.ToString(), "");//
///customer.login.ToString());
///The login field can no longer be used in the ManagedCustomer class within the ManagedCustomerService.
///
}
}
dbConnection.Open();
if (dtClients.Rows.Count != 0)
{
genUtilities.eraseAdWords("Clients");
using (SqlBulkCopy s = new SqlBulkCopy(dbConnection))///inserting campaigns to DB
{
s.DestinationTableName = "Clients";
foreach (var column in dtClients.Columns)
s.ColumnMappings.Add(column.ToString(), column.ToString());
s.WriteToServer(dtClients);
}
}
}
catch (AdWordsApiException ex)
{
ApiException innerException = ex.ApiException as ApiException;
LogFile("Failed to download Client Id's from google server ", "",
innerException.errors.ToString(), innerException.message.ToString());
}
catch (Exception ex)
{
LogFile("Failed to download Client Id's from google server ", "", ex.Data.ToString(), ex.InnerException.Data.ToString());
}
finally
{
if (dbConnection.State == ConnectionState.Open)
{
dbConnection.Close();
}
}