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

制作购物广告组广告

标准购物广告系列

制作购物产品广告包含以下两个步骤:

  1. 创建 ShoppingProductAdInfo 对象,并将其设置为新 Ad 对象的 shopping_product_ad 字段。

  2. 创建 AdGroupAd,并将 ad 字段设置为此前创建的 Ad 对象。

此代码示例演示了如何为标准购物广告系列制作 SHOPPING_PRODUCT_AD 广告组广告。

Java

private String addShoppingProductAdGroupAd(
    GoogleAdsClient googleAdsClient, long customerId, String adGroupResourceName) {
  // Creates a new shopping product ad.
  Ad ad =
      Ad.newBuilder().setShoppingProductAd(ShoppingProductAdInfo.newBuilder().build()).build();
  // Creates a new ad group ad and sets the shopping product ad to it.
  AdGroupAd adGroupAd =
      AdGroupAd.newBuilder()
          // Sets the ad to the ad created above.
          .setAd(ad)
          .setStatus(AdGroupAdStatus.PAUSED)
          // Sets the ad group.
          .setAdGroup(StringValue.of(adGroupResourceName))
          .build();

  // Creates an ad group ad operation.
  AdGroupAdOperation operation = AdGroupAdOperation.newBuilder().setCreate(adGroupAd).build();

  // Issues a mutate request to add an ad group ad.
  try (AdGroupAdServiceClient adGroupAdServiceClient =
      googleAdsClient.getLatestVersion().createAdGroupAdServiceClient()) {
    MutateAdGroupAdResult mutateAdGroupAdResult =
        adGroupAdServiceClient
            .mutateAdGroupAds(Long.toString(customerId), Collections.singletonList(operation))
            .getResults(0);
    System.out.printf(
        "Added a product shopping ad group ad with resource name: '%s'%n",
        mutateAdGroupAdResult.getResourceName());
    return mutateAdGroupAdResult.getResourceName();
  }
}

智能购物广告系列

制作智能购物广告包含以下两个步骤:

  1. 创建 ShoppingSmartAdInfo 对象,并将其设置为新 Ad 对象的 shopping_smart_ad 字段。

  2. 创建 AdGroupAd,并将 ad 字段设置为此前创建的 Ad 对象。

Java

private String addSmartShoppingAdGroupAd(
    GoogleAdsClient googleAdsClient, long customerId, String adGroupResourceName) {
  // Creates a new Smart Shopping ad.
  Ad ad = Ad.newBuilder().setShoppingSmartAd(ShoppingSmartAdInfo.newBuilder().build()).build();
  // Creates a new ad group ad and sets the Smart Shopping ad to it.
  AdGroupAd adGroupAd =
      AdGroupAd.newBuilder()
          // Sets the ad to the ad created above.
          .setAd(ad)
          // Sets the ad group.
          .setAdGroup(StringValue.of(adGroupResourceName))
          .build();

  // Creates an ad group ad operation.
  AdGroupAdOperation operation = AdGroupAdOperation.newBuilder().setCreate(adGroupAd).build();

  // Issues a mutate request to add an ad group ad.
  try (AdGroupAdServiceClient adGroupAdServiceClient =
      googleAdsClient.getLatestVersion().createAdGroupAdServiceClient()) {
    MutateAdGroupAdResult mutateAdGroupAdResult =
        adGroupAdServiceClient
            .mutateAdGroupAds(Long.toString(customerId), Collections.singletonList(operation))
            .getResults(0);
    System.out.printf(
        "Added a Smart Shopping ad group ad with resource name: '%s'%n",
        mutateAdGroupAdResult.getResourceName());
    return mutateAdGroupAdResult.getResourceName();
  }
}