【问题标题】:Retrieve TextAd using Adwords Api使用 Adwords Api 检索 TextAd
【发布时间】:2016-12-25 09:58:56
【问题描述】:

我正在尝试检索 TextAd(标题、Desc1、Desc2、显示 URL 和目标 URL),但失败了。

这是我检索文本广告的代码,它返回 Null 结果

TextAd text = new TextAd();
System.out.println("Headline:"+text.getHeadline());
Syso... etc.

我想检索 TextAd 的所有详细信息,我正在使用 java。

这是我添加 TextAd 的代码

 public static void runExample(
  AdWordsServices adWordsServices, AdWordsSession session, long adGroupId) throws Exception {
// Get the AdGroupAdService.
AdGroupAdServiceInterface adGroupAdService =
    adWordsServices.get(session, AdGroupAdServiceInterface.class);

// Create text ads.
TextAd textAd1 = new TextAd();
textAd1.setHeadline("Luxury Cruise to Mars");
textAd1.setDescription1("Visit the Red Planet in style.");
textAd1.setDescription2("Low-gravity fun for everyone!");
textAd1.setDisplayUrl("www.example.com");
textAd1.setFinalUrls(new String[] {"http://www.example.com/1"});

TextAd textAd2 = new TextAd();
textAd2.setHeadline("Luxury Cruise to Mars");
textAd2.setDescription1("Enjoy your stay at Red Planet.");
textAd2.setDescription2("Buy your tickets now!");
textAd2.setDisplayUrl("www.example.com");
textAd2.setFinalUrls(new String[] {"http://www.example.com/2"});

// Create ad group ad.
AdGroupAd textAdGroupAd1 = new AdGroupAd();
textAdGroupAd1.setAdGroupId(adGroupId);
textAdGroupAd1.setAd(textAd1);

// You can optionally provide these field(s).
textAdGroupAd1.setStatus(AdGroupAdStatus.PAUSED);

AdGroupAd textAdGroupAd2 = new AdGroupAd();
textAdGroupAd2.setAdGroupId(adGroupId);
textAdGroupAd2.setAd(textAd2);


// Create operations.
AdGroupAdOperation textAdGroupAdOperation1 = new AdGroupAdOperation();
textAdGroupAdOperation1.setOperand(textAdGroupAd1);
textAdGroupAdOperation1.setOperator(Operator.ADD);
AdGroupAdOperation textAdGroupAdOperation2 = new AdGroupAdOperation();
textAdGroupAdOperation2.setOperand(textAdGroupAd2);
textAdGroupAdOperation2.setOperator(Operator.ADD);

AdGroupAdOperation[] operations =
    new AdGroupAdOperation[] {textAdGroupAdOperation1, textAdGroupAdOperation2};

// Add ads.
AdGroupAdReturnValue result = adGroupAdService.mutate(operations);

// Display ads.
for (AdGroupAd adGroupAdResult : result.getValue()) {
  System.out.println("Ad with id  \"" + adGroupAdResult.getAd().getId() + "\"" + " and type \""
      + adGroupAdResult.getAd().getAdType() + "\" was added.");
}

}

如何从 adwords 中检索这些值。 这是我从 adword 中检索数据的选择器

SelectorBuilder builder = new SelectorBuilder();
Selector selector = builder
    .fields(AdGroupAdField.Id, AdGroupAdField.AdGroupId, AdGroupAdField.Status,
            AdGroupAdField.Description1,AdGroupAdField.Description2,AdGroupAdField.Headline)
    .orderAscBy(AdGroupAdField.Id)
    .offset(offset)
    .limit(PAGE_SIZE)
    .equals(AdGroupAdField.AdGroupId, adGroupId.toString())
    .in(AdGroupAdField.Status, "ENABLED", "PAUSED", "DISABLED")
    .equals("AdType", "TEXT_AD")
    .build();

【问题讨论】:

  • 您能提供更多代码吗?这里没有发生太多事情,所以希望标题为空。我所看到的只是您正在创建一个新的空对象,然后期望它具有值?
  • 其实我不知道如何获取特定广告组的标题、Desc1/2。如果你能提供一个例子,我将非常感激。主要问题:如何检索我的 TextAd 的标题等
  • 您的问题非常广泛。我想你需要先去看看如何使用 Adwords API:developers.google.com/adwords/api/docs/clientlibraries
  • 我知道如何使用它。我只是对如何获取文本广告的标题等感到困惑。我只能获取 textAd 的显示 URL。
  • 看来您需要从 API 填充 TextAd 对象,然后您才能获取属性值。通过说“new TextAd()”,您将得到一个空对象。这不可能是你所有的代码?

标签: google-ads-api


【解决方案1】:

Typecast adGroupAd.getAd() 到 TextAd 然后你可以得到标题和其他方法。

TextAd textAd = (TextAd)adGroupAd.getAd();
textAd.getHeadline();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多