do {
// Retrieve ad group ads one page at a time, continuing to request pages
// until all ad group ads have been retrieved.
$page = $adGroupAdService->get($selector);
// Print out some information for each ad group ad.
if ($page->getEntries() !== null) {
$totalNumEntries = $page->getTotalNumEntries();
foreach ($page->getEntries() as $adGroupAd) {
$adGroupAdService =
$adWordsServices->get($session, AdGroupAdService::class);
$operations = [];
// Create ad using an existing ID. Use the base class Ad instead of
TextAd
// to avoid having to set ad-specific fields.
$ad = new ExpandedTextAd();
$ad->setId($adGroupAd->getAd()->getId());
// Create ad group ad.
$adGroupAd = new AdGroupAd();
$adGroupAd->setAdGroupId($adGroupId);
$adGroupAd->setAd($ad);
// Update the status to PAUSED.
$adGroupAd->setStatus(AdGroupAdStatus::PAUSED);
// Create ad group ad operation and add it to the list.
$operation = new AdGroupAdOperation();
$operation->setOperand($adGroupAd);
$operation->setOperator(Operator::SET);
$operations[] = $operation;
// Pause the ad on the server.
$adGroupAd = $adGroupAdService->mutate($operations)->getValue()[0];
printf(
"Expanded text ad with ID %d, status '%s', and headline "
. "'%s - %s' was found.\n",
$adGroupAd->getAd()->getId(),
$adGroupAd->getStatus(),
$adGroupAd->getAd()->getHeadlinePart1(),
$adGroupAd->getAd()->getHeadlinePart2()
);
}
}
Do I need to change the $adGroupAd->setAdGroupId($adGroupId); as well?
I am getting an [AdError.CANNOT_USE_AD_SUBCLASS_FOR_OPERATOR @
operations[0].operand.ad] error.
On Monday, March 13, 2017 at 1:58:04 PM UTC-5, Shwetha Vastrad (AdWords API
Team) wrote:
>
> Hi Dan,
>
> In your code, I see that when you create the ExpandedTextAd object, you
> are setting the AdGroupAd object as the AdId. Please change this line of
> code to the one below and retry the request and let me know if it works.
>
> $ad->setId($adGroupAd->getAd()->getId());
>
>
> Regards,
> Shwetha, AdWords API Team.
>
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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 [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 Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
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/83567b28-7b11-4539-ac37-375fa1fdea63%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.