开发者

How can I tell the Google Adwords API which client/account in my MCC I am querying?

开发者 https://www.devze.com 2023-04-01 16:48 出处:网络
Using the latest PHP CLient Library (v2.6.3) I can\'t seem to figure out to get all campaigns for a client in my MCC (my client center) account.

Using the latest PHP CLient Library (v2.6.3) I can't seem to figure out to get all campaigns for a client in my MCC (my client center) account.

I can easily get all accounts via:

$user = new AdWordsUser(NULL, $email, $password, $devToken, $applicationToken, $userAgent, NULL, $settingsFile);

$service = $user->GetServicedAccountService();
$selector = new ServicedAccountSelector();
$selector->enablePaging = false;

$graph = $service->get($selector);
$accounts = $graph->accounts; // all accounts!

Now that I've done that, I want to get all the campaigns within each account. Running the code as documented here doesn't work.

// Get the CampaignService.
// ** Different than example because example calls a private method ** //
$campaignService = $user->GetCampaignService('v201101');

// Create selector.
$selector = new Selector();
$selector->fields = array('Id', 'Name');
$selector->ordering = array(new OrderBy('Name', 'ASCENDING'));

// Get all campaigns.
$page = $campaignService->get($selector);

// Display campaigns.
if (isset($page->entries)) {
    foreach ($page->entries as $campaign) {
        print 'Campaign with name "' . $campaign->name . '" and id "'
            . $campaign-&g开发者_StackOverflow中文版t;id . "\" was found.\n";
    }
}

All the above code will do is throw an error:

Fatal error: Uncaught SoapFault exception: [soap:Server] QuotaCheckError.INVALID_TOKEN_HEADER @ message=null stack=com.google.ads.api.authserver.common.AuthException at com.go;

I have a feeling that the reason this fails is that GetCampaignService needs an account's id...but I can't figure out how to specify this id.

What am I doing wrong?


The problem ended up being that I was given the wrong developerToken. I didn't think INVALID_TOKEN_HEADER really meant what it said because SOME calls still worked with the faulty token. I don't know why.

0

精彩评论

暂无评论...
验证码 换一张
取 消