← 返回目录
来源:Google Ads API 官方文档 · 中文版 · 本地归档

制作购物广告组广告

为标准购物广告系列制作购物产品广告包含以下两个步骤:

  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(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();
  }
}

      

C#

private string AddProductShoppingAdGroupAd(GoogleAdsClient client, long customerId,
    string adGroupResourceName)
{
    // Get the AdGroupAdService.
    AdGroupAdServiceClient adGroupAdService = client.GetService(
        Services.V25.AdGroupAdService);

    // Creates a new shopping product ad.
    Ad ad = new Ad()
    {
        ShoppingProductAd = new ShoppingProductAdInfo()
        {
        }
    };

    // Creates a new ad group ad and sets the shopping product ad to it.
    AdGroupAd adGroupAd = new AdGroupAd()
    {
        // Sets the ad to the ad created above.
        Ad = ad,

        Status = AdGroupAdStatus.Paused,

        // Sets the ad group.
        AdGroup = adGroupResourceName
    };

    // Creates an ad group ad operation.
    AdGroupAdOperation operation = new AdGroupAdOperation()
    {
        Create = adGroupAd
    };

    // Issues a mutate request to add an ad group ad.
    MutateAdGroupAdResult mutateAdGroupAdResult = adGroupAdService.MutateAdGroupAds(
        customerId.ToString(), new AdGroupAdOperation[] { operation }).Results[0];
    Console.WriteLine("Added a product shopping ad group ad with resource name: '{0}'.",
        mutateAdGroupAdResult.ResourceName);
    return mutateAdGroupAdResult.ResourceName;
}
      

PHP

private static function addShoppingProductAdGroupAd(
    GoogleAdsClient $googleAdsClient,
    int $customerId,
    string $adGroupResourceName
) {
    // Creates a new shopping product ad.
    $ad = new Ad(['shopping_product_ad' => new ShoppingProductAdInfo()]);

    // Creates a new ad group ad and sets the shopping product ad to it.
    $adGroupAd = new AdGroupAd([
        'ad' => $ad,
        'status' => AdGroupAdStatus::PAUSED,
        // Sets the ad group.
        'ad_group' => $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(
        MutateAdGroupAdsRequest::build($customerId, [$adGroupAdOperation])
    );

    /** @var AdGroupAd $addedAdGroupAd */
    $addedAdGroupAd = $response->getResults()[0];
    printf(
        "Added a shopping product ad group ad with resource name '%s'.%s",
        $addedAdGroupAd->getResourceName(),
        PHP_EOL
    );
}
在接这个接口时卡住了?
Stuck wiring this API into production? We build ad-delivery tooling on these platforms — campaign automation, reporting pipelines, error-handling and migration between API versions.
联系我们 · Talk to us 每日平台更新简报 →