Reputation: 3589
I am trying to create ad for adgroup but getting following error:
faultString: [AdError.INVALID_AD_TYPE @ operations[0].operand.ad]
this is my code:
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;
}
I was looking into Ad types which should be supplied to API but no luck to find it. Could you please point me to my problem?
Upvotes: 0
Views: 659
Reputation: 1833
I've seen a problem that should be similar to this problem. It's setting the type of the ad. You should not set the type using:
newAd.setAdType(adType);
But instead create a certain type of Ad by creating a different object based on the adType string you're recieving as a parameter. Perhaps you could even pass an object with the parent type Ad. As you're reading this it probably sounds a bit vague. Let me demonstrate:
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;
}
This way the Adwords library will take care of the type internally.
This is also done in the following PHP example (it should quite the same for Java), they use a TextAd instead of just an Ad. See line 53
P.S. I know this question is a bit old, but it fixed the problem for me, so it might also do so for others ;)
Upvotes: 0
Reputation: 425
In Google AdWords, there are several different advertising networks that a campaign can target. Search Network is for text ads; Display Network is for image ads. Some campaigns only target a single network, while others target both.
It is likely you are trying to upload a text ad to a "Display Network only" campaign.
It is also worth noting that, when indicating ad type within a mutate operation, you actually specify xsi:type rather than Ad.Type (looks like this would be handled in your AdGroupAd class, but just thought I'd be thorough!).
Upvotes: 2