Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google api 广告词广告类型问题_Google Api_Google Ads Api_Adwords Api V201109 - Fatal编程技术网

Google api 广告词广告类型问题

Google api 广告词广告类型问题,google-api,google-ads-api,adwords-api-v201109,Google Api,Google Ads Api,Adwords Api V201109,我正在尝试为adgroup创建广告,但出现以下错误: faultString:[AdError.INVALID_AD_TYPE@operations[0]。操作数.AD] 这是我的代码: AdGroupAdProxy adGroupAdProxy= new AdGroupAdProxy(session, services); adGroupAdProxy.createNewAd("TextAd", "http://example/12123.html", adGroupId); public

我正在尝试为adgroup创建广告,但出现以下错误:
faultString:[AdError.INVALID_AD_TYPE@operations[0]。操作数.AD]

这是我的代码:

AdGroupAdProxy adGroupAdProxy= new AdGroupAdProxy(session, services);
adGroupAdProxy.createNewAd("TextAd", "http://example/12123.html", adGroupId);

public Long createNewAd(String adType, String displayUrl, Long adGroupId) throws ApiException, RemoteException{

Ad newAd = new Ad();
newAd.setAdType(adType);
newAd.setDisplayUrl(displayUrl);

AdGroupAd newAdGroupAd = new AdGroupAd();
newAdGroupAd.setAd(newAd);
newAdGroupAd.setAdGroupId(adGroupId);

AdGroupAdOperation operations = new AdGroupAdOperation();
operations.setOperand(newAdGroupAd);
operations.setOperator(Operator.ADD);

    Long adId = adGroupAdService.mutate(new AdGroupAdOperation[] {operations}).getValue(0).getAd().getId();
    return adId;

}

我正在研究应该提供给API的广告类型,但没有找到它。你能指出我的问题吗

在谷歌AdWords中,有几个不同的广告网络可以作为广告活动的目标。搜索网络是为文字广告;显示网络用于图像广告。一些活动仅针对单个网络,而其他活动则同时针对两个网络

很可能您正试图将文字广告上载到“仅显示网络”活动


还值得注意的是,当在mutate操作中指示ad类型时,实际上指定的是xsi:type而不是ad.type(看起来这将在AdGroupAd类中处理,但我认为我会彻底解决!)。

我看到了一个与此问题类似的问题。它正在设置广告的类型。您不应使用以下方式设置类型:

newAd.setAdType(adType);
而是通过基于作为参数接收的adType字符串创建不同的对象来创建特定类型的Ad。也许你甚至可以传递一个带有父类型广告的对象。当你读这篇文章的时候,它可能听起来有点模糊。让我示范一下:

AdGroupAdProxy adGroupAdProxy= new AdGroupAdProxy(session, services);
adGroupAdProxy.createNewAd(new TextAd(), "http://example/12123.html", adGroupId);

public Long createNewAd(Ad newAd, String displayUrl, Long adGroupId) throws ApiException, RemoteException{

newAd.setDisplayUrl(displayUrl);

AdGroupAd newAdGroupAd = new AdGroupAd();
newAdGroupAd.setAd(newAd);
newAdGroupAd.setAdGroupId(adGroupId);

AdGroupAdOperation operations = new AdGroupAdOperation();
operations.setOperand(newAdGroupAd);
operations.setOperator(Operator.ADD);

    Long adId = adGroupAdService.mutate(new AdGroupAdOperation[] {operations}).getValue(0).getAd().getId();
    return adId;

}
这样,Adwords库将在内部处理该类型

这也在下面的PHP示例中完成(Java也应该如此),它们使用TextAd而不仅仅是Ad

另外,我知道这个问题有点老了,但它解决了我的问题,所以它也可能解决了其他人的问题;)