I used following code for adding Ad to a AdGroup.
////////////////////////////////////////////////////////////////////////////////////////////////
const AD_GROUP_ID = '46481580951';
public static function runExample(AdWordsServices $adWordsServices, AdWordsSession $session, $adGroupId) {
$adGroupAdService = $adWordsServices->get($session, AdGroupAdService::class);
// Create the expanded Dynamic Search Ad. This ad will have its headline
// and final URL auto-generated at serving time according to domain name
// specific information provided by DynamicSearchAdsSetting at the
// campaign level.
$expandedDSA = new ExpandedDynamicSearchAd();
// Set the ad description.
$expandedDSA->setDescription('Dummy description');
// Create the ad group ad.
$adGroupAd = new AdGroupAd();
$adGroupAd->setAdGroupId($adGroupId);
$adGroupAd->setAd($expandedDSA);
// Create the operation.
$operation = new AdGroupAdOperation();
$operation->setOperator(Operator::ADD);
$operation->setOperand($adGroupAd);
// Create the ad on the server and print some information.
$result = $adGroupAdService->mutate([$operation]);
$newAdGroupAd = $result->getValue()[0];
$expandedDSA = $newAdGroupAd->getAd();
printf(
"Expanded Dynamic Search Ad with ID %d and description '%s' was"
. " added.\n", $expandedDSA->getId(), $expandedDSA->getDescription()
);
}
//////////////////////////////////////////////////////////////////////////////
I got 2 error ,
const AD_GROUP_ID = '46481580951'; is converted integer.
Can anyone help me out with the issue.