Hi Guys,
I've got a laravel job set up that runs at midnight to enable campaigns
that the same application had paused earlier when their budget goes over.
public function handle()
{
$clientId = "xxxx";
$clientSecret = "xxxx";
$refreshToken = "xxxx";
$developerToken = "xxxx";
$oAuth2Credential = (new OAuth2TokenBuilder())
->withClientId($clientId)
->withClientSecret($clientSecret)
->withRefreshToken($refreshToken)
->build()
;
$googleAdsClient = (new GoogleAdsClientBuilder())
->withDeveloperToken($developerToken)
->withLoginCustomerId($this->loginCustomerId)
->withOAuth2Credential($oAuth2Credential)
->build()
;
try{
DB::table('actions')->insert([
'type' => 'campaignEnabled',
'accountId' => $this->accountId,
'campaignId' => $this->campaignId,
'date' => (new \DateTime())->format("Y-m-d"),
'time' => new \DateTime('now', new \DateTimeZone("GMT")),
'hash' => md5(json_encode([
'budget' => $this->campaignBudget / 1000000,
])),
'data' => json_encode([
'budget' => $this->campaignBudget / 1000000,
'accountName' => $this->accountName,
'campaignName' => $this->campaignName,
]),
]);
$campaign = new Campaign([
'resource_name' => ResourceNames::forCampaign($this->
accountId, $this->campaignId),
'status' => CampaignStatus::ENABLED
]);
$campaignOperation = new CampaignOperation();
$campaignOperation->setUpdate($campaign);
$campaignOperation->setUpdateMask(FieldMasks::allSetFieldsOf(
$campaign));
$campaignServiceClient = $googleAdsClient->
getCampaignServiceClient();
$response = $campaignServiceClient->mutateCampaigns(
$this->accountId,
[$campaignOperation]
);
}catch (\Illuminate\Database\QueryException $e){
$errorCode = $e->errorInfo[1];
if($errorCode !== 1062){
throw $e;
}
}
}
As you can see above its not largley dissimilar to the standard "modify
campaign" example, and is identical to the pause logic, which works just
fine. the only diffference is that CampaignStatus is set to PAUSED not
ENABLED.
That part runs absolutley fine, however this one provides the following
error;
Exception: Expect Google\Ads\GoogleAds\V3\Services\CampaignOperation. in
/home/ppcagzkv/public_html/vendor/google/protobuf/src/Google/Protobuf/Internal/GPBUtil.php:197
Stack trace:
#0
/home/ppcagzkv/public_html/vendor/google/protobuf/src/Google/Protobuf/Internal/RepeatedField.php(183):
Google\Protobuf\Internal\GPBUtil::checkMessage(Object(Google\Ads\GoogleAds\V4\Services\CampaignOperation),
'Google\\Ads\\Goog...')
#1
/home/ppcagzkv/public_html/vendor/google/protobuf/src/Google/Protobuf/Internal/GPBUtil.php(209):
Google\Protobuf\Internal\RepeatedField->offsetSet(NULL,
Object(Google\Ads\GoogleAds\V4\Services\CampaignOperation))
#2
/home/ppcagzkv/public_html/vendor/googleads/google-ads-php/src/Google/Ads/GoogleAds/V3/Services/MutateCampaignsRequest.php(118):
Google\Protobuf\Internal\GPBUtil::checkRepeatedField(Array, 11,
'Google\\Ads\\Goog...')
#3
/home/ppcagzkv/public_html/vendor/googleads/google-ads-php/src/Google/Ads/GoogleAds/V3/Services/Gapic/CampaignServiceGapicClient.php(349):
Google\Ads\GoogleAds\V3\Services\MutateCampaignsRequest->setOperations(Array)
#4 /home/ppcagzkv/public_html/app/Jobs/enableCampaign.php(101):
Google\Ads\GoogleAds\V3\Services\Gapic\CampaignServiceGapicClient->mutateCampaigns('6888044290',
Array)
#5 [internal function]: App\Jobs\enableCampaign->handle()
The file above is enableCampaign.php and line 101 is - [$campaignOperation]
I dont understand why this one is giving an error, while the other works
just fine, any help would be appreciated.
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
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 and Google Ads API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/adwords-api/fd366537-7225-4a81-b462-a2343d07637co%40googlegroups.com.