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
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 :)