public static void AdWords_DisplayCampaignsToConsole(string customerID)
{
// Create the user.
AdWordsUser user = new AdWordsUser();
(user.Config as AdWordsAppConfig).DeveloperToken = "(omitted)";
(user.Config as AdWordsAppConfig).OAuth2RefreshToken = "(omitted)";
(user.Config as AdWordsAppConfig).OAuth2ClientId = "(omitted)";
(user.Config as AdWordsAppConfig).OAuth2ClientSecret = "(omitted)";
(user.Config as AdWordsAppConfig).ClientCustomerId = "(omitted)";
// Create the service connector.
CampaignService campaignService = (CampaignService)user.GetService(AdWordsService.v201705.CampaignService);
// Create the selector.
Selector selector = new Selector();
selector.paging = Paging.Default;
// Create the page.
CampaignPage page = new CampaignPage();
// Try to get the campaign list.
try
{
// Repeat the request until all pages are received.
do
{
// Get the campaigns.
page = campaignService.get(selector);
// Display the results.
if (page != null && page.entries != null)
{
// Loop through all campaigns in this current page
int i = selector.paging.startIndex;
foreach (Campaign campaign in page.entries)
{
// Output the compani id, name, and status to the console
Console.WriteLine($"{(i + 1).ToString()}) Campaign with id = '{campaign.id.ToString()}', name = '{campaign.name}' and status = '{campaign.status.ToString()}'" + " was found."); i++;
}
}
selector.paging.IncreaseOffset();
} while (selector.paging.startIndex < page.totalNumEntries);
// Output the totals
Console.WriteLine("Number of campaigns found: {0}", page.totalNumEntries);
}
catch (Exception ex)
{
// throw exception
throw new System.ApplicationException("Failed to retrieve campaigns", ex);
}
}