Google Ads API is returning to beta status. Please read our blog post for more details.

制作酒店广告组广告

制作酒店广告包含以下两个步骤:

  1. 制作一个 Ad,并将其 hotel_ad 设置为 HotelAdInfo 的实例。

  2. 制作一个 AdGroupAd,并将之前制作的 Ad 与其相关联。

PHP
private static function addHotelAdGroupAd(
    GoogleAdsClient $googleAdsClient,
    $customerId,
    $adGroupResourceName
) {
    // Creates a new hotel ad.
    $ad = new Ad([
        'hotel_ad' => new HotelAdInfo(),
    ]);

    // Creates a new ad group ad and sets the hotel ad to it.
    $adGroupAd = new AdGroupAd([
        'ad' => $ad,
        'status' => AdGroupAdStatus::PAUSED,
        // Sets the ad group.
        'ad_group' => new StringValue(['value' => $adGroupResourceName])
    ]);

    // Creates an ad group ad operation.
    $adGroupAdOperation = new AdGroupAdOperation();
    $adGroupAdOperation->setCreate($adGroupAd);

    // Issues a mutate request to add an ad group ad.
    $adGroupAdServiceClient = $googleAdsClient->getAdGroupAdServiceClient();
    $response = $adGroupAdServiceClient->mutateAdGroupAds($customerId, [$adGroupAdOperation]);

    /** @var AdGroupAd $addedAdGroupAd */
    $addedAdGroupAd = $response->getResults()[0];
    printf(
        "Added a hotel ad group ad with resource name '%s'.%s",
        $addedAdGroupAd->getResourceName(),
        PHP_EOL
    );
}