Hi! 

I've tried to make a script that update existing account budget and, it 
seems, that does not work. 
*Can you help me please, what could be wrong?*

My code is based on:
1) Add budget proposal example from library
2) On this code from 
docs: 
https://developers.google.com/google-ads/api/docs/billing/account-budgets?hl=en#update
 

Logger is enabled (and logging examples from library), but, unfortunately, 
not this script. Idk why. 

Full code:


<?php


namespace Google\Ads\GoogleAds\Examples\Billing;

require __DIR__ . '/../../vendor/autoload.php';

use GetOpt\GetOpt;
use Google\Ads\GoogleAds\Examples\Utils\ArgumentNames;
use Google\Ads\GoogleAds\Examples\Utils\ArgumentParser;
use Google\Ads\GoogleAds\Lib\OAuth2TokenBuilder;
use Google\Ads\GoogleAds\Lib\V12\GoogleAdsClient;
use Google\Ads\GoogleAds\Lib\V12\GoogleAdsClientBuilder;
use Google\Ads\GoogleAds\Lib\V12\GoogleAdsException;
use Google\Ads\GoogleAds\Util\V12\ResourceNames;
use 
Google\Ads\GoogleAds\V12\Enums\AccountBudgetProposalTypeEnum\AccountBudgetProposalType;
use Google\Ads\GoogleAds\V12\Enums\TimeTypeEnum\TimeType;
use Google\Ads\GoogleAds\V12\Errors\GoogleAdsError;
use Google\Ads\GoogleAds\V12\Resources\AccountBudgetProposal;
use Google\Ads\GoogleAds\V12\Services\AccountBudgetProposalOperation;
use Google\ApiCore\ApiException;
use Google\Protobuf\FieldMask;
use Google\Ads\GoogleAds\Util\FieldMasks;



class AddAccountBudgetProposal
{
    private const CUSTOMER_ID = '3721199407';
    //private const BILLING_SETUP_ID = 'INSERT_BILLING_SETUP_ID_HERE';

    public static function main()
    {
        // Either pass the required parameters for this example on the 
command line, or insert them
        // into the constants above.
        $options = (new ArgumentParser())->parseCommandArguments([
            ArgumentNames::CUSTOMER_ID => GetOpt::REQUIRED_ARGUMENT,
            //ArgumentNames::BILLING_SETUP_ID => GetOpt::REQUIRED_ARGUMENT
        ]);

        // Generate a refreshable OAuth2 credential for authentication.
        $oAuth2Credential = (new OAuth2TokenBuilder())->fromFile()->build();

        // Construct a Google Ads client configured from a properties file 
and the
        // OAuth2 credentials above.
        $googleAdsClient = (new GoogleAdsClientBuilder())->fromFile()
            ->withOAuth2Credential($oAuth2Credential)
            ->build();

        try {
            self::runExample(
                $googleAdsClient,
                $options[ArgumentNames::CUSTOMER_ID] ?: self::CUSTOMER_ID,
                //$options[ArgumentNames::BILLING_SETUP_ID] ?: 
self::BILLING_SETUP_ID
            );
        } catch (GoogleAdsException $googleAdsException) {
            printf(
                "Request with ID '%s' has failed.%sGoogle Ads failure 
details:%s",
                $googleAdsException->getRequestId(),
                PHP_EOL,
                PHP_EOL
            );
            foreach 
($googleAdsException->getGoogleAdsFailure()->getErrors() as $error) {
               
                printf(
                    "\t%s: %s%s",
                    $error->getErrorCode()->getErrorCode(),
                    $error->getMessage(),
                    PHP_EOL
                );
            }
            exit(1);
        } catch (ApiException $apiException) {
            printf(
                "ApiException was thrown with message '%s'.%s",
                $apiException->getMessage(),
                PHP_EOL
            );
            exit(1);
        }
    }


    public static function runExample(
        GoogleAdsClient $googleAdsClient,
        int $customerId

    ) {

//Update budget proposal
$accountBudget = 'customers/3721199407/accountBudgets/6885650342';
$increaseAmount = 500000000;
$accountBudgetProposal = new AccountBudgetProposal([
  'proposal_type' => AccountBudgetProposalType::UPDATE,
  'account_budget' => $accountBudget,
  'proposed_spending_limit_micros' =>
   $increaseAmount]);

$accountBudgetProposalOperation = new AccountBudgetProposalOperation();
$accountBudgetProposalOperation->setCreate($accountBudgetProposal);
$accountBudgetProposalOperation->setUpdateMask(
  FieldMasks::allSetFieldsOf($accountBudgetProposal)
);

    }

}

AddAccountBudgetProposal::main();

?>


Pray for your help :)

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads 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+unsubscr...@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 
"Google Ads API and AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to adwords-api+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/d51938b9-a9f7-4a4d-bd5d-5223b0377083n%40googlegroups.com.
  • Up... Алексей Рябиков
    • ... 'Google Ads API Forum Advisor' via Google Ads API and AdWords API Forum

Reply via email to