* @param adGroupId the id of the parent ad group
* @return the id of the created ad
*/
public long createTextAd(long adGroupId) throws Exception {
// Get the AdGroupAdService.
AdGroupAdServiceInterface adGroupAdService =
user.getService(AdWordsService.V201008.ADGROUP_AD_SERVICE);
// Create text ad.
TextAd textAd = new TextAd();
textAd.setHeadline("Luxury Cruise to Mars");
textAd.setDescription1("Visit the Red Planet in style.");
textAd.setDescription2("Low-gravity fun for everyone!");
textAd.setDisplayUrl("www.example.com");
textAd.setUrl("http://www.example.com");
// Create ad group ad.
AdGroupAd textAdGroupAd = new AdGroupAd();
textAdGroupAd.setAdGroupId(adGroupId);
textAdGroupAd.setAd(textAd);
// Create operations.
AdGroupAdOperation textAdGroupAdOperation = new AdGroupAdOperation();
textAdGroupAdOperation.setOperand(textAdGroupAd);
textAdGroupAdOperation.setOperator(Operator.ADD);
AdGroupAdOperation[] operations = new AdGroupAdOperation[] {textAdGroupAdOperation};
// Add new TextAd and return its ID.
return adGroupAdService.mutate(operations).getValue()[0].getAd().getId();
}