Wednesday, 21 September 2016

Retrieve budget spent and end date for all billing accounts

Hi,

I am trying to get all the budgets from all billing accounts used under an MCC account. I saw that I should use the BudgetOrderService to get BudgetOrders, but it returns me an empty page. I can get the billing accounts from the BudgetOrderService->getBillingAccounts, what am I doing wrong? I am using the most recent version of the API and had nothing before, I am also whitelisted.

Here is my code (PHP) : 

 public function getBudgets(AdWordsUser $user) {
        
        // Get the service, which loads the required classes.
        $budgetOrderService = $user->GetService('BudgetOrderService', ADWORDS_VERSION);

        // Create selector.
        $selector = new Selector();
        $selector->fields = array('id', 'spendingLimit', 'endDateTime');
        
        // Create paging controls.
        $selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);
        
        do {
            // Make the get request.
            $page = $budgetOrderService->get($selector);

            print_r($page); // Here it says BudgetOrderPage Object ( [entries] => [totalNumEntries] => 0

            // Show the information for all budgets
            if (isset($page->entries)) {
                foreach ($page->entries as $budgetOrder) {
                    echo $budgetOrder->id;
                    echo $budgetOrder->spendingLimit;
                    echo $budgetOrder->endDateTime;
                }   
            }
        
            // Advance the paging index.
            $selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE;
        } while ($page->totalNumEntries > $selector->paging->startIndex);
    }
}

--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+:
https://googleadsdeveloper.blogspot.com/
https://plus.google.com/+GoogleAdsDevelopers/posts
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
 
You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
---
You received this message because you are subscribed to the Google Groups "AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-api+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/adwords-api.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-api/c74d13cf-6564-4274-b22a-477c51325024%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment