Ads API error for enabling a campaign

59 views
Skip to first unread message

beyond Clicks

unread,
Aug 27, 2020, 8:31:07 AM8/27/20
to AdWords API and Google Ads API Forum
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.

Google Ads API Forum Advisor Prod

unread,
Aug 27, 2020, 12:13:37 PM8/27/20
to byon...@gmail.com, adwor...@googlegroups.com
Hi,

Thank you for reaching out to us. I see you're encountering an error. Could you elaborate on what error you encounter and also provide us with the request and response logs for where the error occurs?

Thank you,

Google Logo
Bryan Li
Google Ads API Team
 


ref:_00D1U1174p._5004Q23v7SS:ref
Reply all
Reply to author
Forward
0 new messages