I can get Managed Accounts, but I can't get Campaigns

76 views
Skip to first unread message

rootde...@gmail.com

unread,
Jun 12, 2017, 3:03:51 PM6/12/17
to AdWords API Forum, s...@extranerds.com
The following C# code outputs a list of managed accounts. This works fine, as it outputs all 50+ managed accounts (please read on)...

public static void AdWords_DisplayManagedCustomersToConsole()
{
// 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.
ManagedCustomerService managedCustomerService = (ManagedCustomerService)user.GetService(AdWordsService.v201705.ManagedCustomerService);

// Create the selector.
Selector selector = new Selector();
selector.fields = new String[] { ManagedCustomer.Fields.CustomerId, ManagedCustomer.Fields.Name };
selector.paging = Paging.Default;

// Create the page.
ManagedCustomerPage page = new ManagedCustomerPage();

// Try to get the customer list.
try
{
// Repeat the request until all pages are received.
do
{
// Get the campaigns.
page = managedCustomerService.get(selector);

// Display the results.
if (page != null && page.entries != null)
{
// Loop through all customers in this current page
int i = selector.paging.startIndex;
foreach (ManagedCustomer customer in page.entries)
{
// Output the login, customer id, and name to the console
Console.WriteLine($"{(i + 1).ToString()}) Customer with customerID = '{customer.customerId.ToString()}' and name = '{customer.name}'" + " was found.");
i++;
}
}
selector.paging.IncreaseOffset();
} while (selector.paging.startIndex < page.totalNumEntries);

// Output the totals
Console.WriteLine("Number of customers found: {0}", page.totalNumEntries);
}
catch (Exception ex)
{
// throw exception
throw new System.ApplicationException("Failed to retrieve managed customers", ex);
}
}

However, the following C# code, which is nearly identical (all omitted data is the same in both code samples). The only difference is that this code is supposed to get a list of campaigns for one customer (the main customer account) instead of a list of managed accounts. This does not work....

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.fields = new String[] { Campaign.Fields.Id, Campaign.Fields.Name, Campaign.Fields.Status };
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);
}
}

There are no errors, but the results come back empty. No campaigns to list. This is odd, because I'm looking at this customer account in the AdWords web interface and I see lots of campaigns of all different types.

What could be allowing the first code block to produce results but not the second code block? What am I missing here?

Sreelakshmi Sasidharan (AdWords API Team)

unread,
Jun 12, 2017, 5:30:56 PM6/12/17
to AdWords API Forum, s...@extranerds.com
Hi, 

Could you confirm if you are making the CampaignService API call against the manager account or one of its client accounts? Please note that the CampaignService needs to be issued against a client account.The API calls against a manager account will not return results. If that is not the issue here, could you please enable logging and pass on the SOAP logs (request/response) along with the client customer Id of the account that you are making the API calls against? 

Please use Reply privately to the author while replying.

Thanks,
Sreelakshmi, AdWords API Team
Reply all
Reply to author
Forward
0 new messages