Hello,
When I call the Google Ads API(V2) to create an AdGroupAd, throw an error about “This operation is not permitted on this campaign type” .
before this,I have set the Campaign advertising_channel_type=MULTI_CHANNEL,advertising_channel_sub_type=APP_CAMPAIGN,AdGroup type=UNSPECIFIED.
and here is my code about create AdGroupAd:
public static function runExample(
GoogleAdsClient $googleAdsClient,
$customerId,
$adGroupId
) {
$adGroupResourceName = new StringValue(['value' => ResourceNames::forAdGroup($customerId, $adGroupId)]);
$asset_operations = [];
$ad_operations = [];
$asset = new Asset([
'youtube_video_asset' => new YoutubeVideoAsset([
'youtube_video_id' => new StringValue(['value' => 'adZeOuXpqIQ'])
]),
'type' => AssetType::YOUTUBE_VIDEO,
]);
$assetOperation = new AssetOperation();
$assetOperation->setCreate($asset);
$asset_operations[] = $assetOperation;
$assetServiceClient = $googleAdsClient->getAssetServiceClient();
$response = $assetServiceClient->mutateAssets($customerId,$asset_operations);
foreach ($response->getResults() as $asset) {
$assetResourceName = $asset->getResourceName();
}
$appAdInfo = new AppAdInfo([
'youtube_videos'=>[
new AdVideoAsset([
'asset'=>new StringValue(['value' => $assetResourceName]),
])
],
]);
//Sets the expanded text ad info on an Ad.
$ad = new Ad([
'type'=>AdType::APP_AD,
'app_ad'=>$appAdInfo,
]);
// Creates an ad group ad to hold the above ad.
$adGroupAd = new AdGroupAd([
'ad_group' => $adGroupResourceName,
'status' => AdGroupAdStatus::PAUSED,
'ad'=>$ad,
]);
// Creates an ad group ad operation and add it to the operations array.
$adGroupAdOperation = new AdGroupAdOperation();
$adGroupAdOperation->setCreate($adGroupAd);
$ad_operations[] = $adGroupAdOperation;
// Issues a mutate request to add the ad group ads.
$adGroupAdServiceClient = $googleAdsClient->getAdGroupAdServiceClient();
$response = $adGroupAdServiceClient->mutateAdGroupAds($customerId, $ad_operations);
foreach ($response->getResults() as $addedAdGroupAd) {
/** @var AdGroupAd $addedAdGroupAd */
printf(
"Expanded text ad was created with resource name: '%s'%s",
$addedAdGroupAd->getResourceName(),
PHP_EOL
);
}
}
}
How to solve this problem?
Thank you