Hi All,
I am trying to use the following code, in C#, to upload some ImageAds to AdWords; however, it appears that I am using the wrong service. However, using a MediaService forces me to change method from mutate to upload, the argument from List<AdGroupAdOperation> to Media[], and then I have to change the type from ImageAd to Image, otherwise I can't put it in the array, and then I can't assign certain information, such as AdGroupId, which I need to specify.
Does anyone know where I'm going wrong or what I should be doing instead to achieve my goal of putting certain ImageAds in a certain AdGroup?
Thanks,
Conor
========================== Code ==========================
var operations = new List<AdGroupAdOperation>();
foreach (var generatedAd in generatedAds)
{
// create a new image to put in the imageAd
var image = new Image
{
data = generatedAd.Image.FileData,
type = MediaMediaType.IMAGE
};
// create a new image ad
var imageAd = new ImageAd
{
image = image,
displayUrl = DisplayURL,
url = generatedAd.Ad.Url
};
var imageAdGroupAd = new AdGroupAd
{
adGroupId = (long)generatedAd.Ad.AdwordsAdGroupId
};
// prepare to add the new image ad to the ad words group
var operation = new AdGroupAdOperation
{
@operator = Operator.ADD,
operand = imageAdGroupAd
};
operations.Add(operation);
}
try
{
((AdGroupAdService)user.GetService(AdWordsService.v201406.AdGroupAdService))
.mutate(operations.ToArray());
}
========================== Code ==========================