public void Run(AdWordsUser user)
{
// Get the MediaService.
MediaService mediaService = (MediaService) user.GetService(
AdWordsService.v201306.MediaService);
// Create the image.
Image image = new Image();
image.data = MediaUtilities.GetAssetDataFromUrl("http://goo.gl/HJM3L");
image.type = MediaMediaType.IMAGE;
try {
// Upload the image.
Media[] result = mediaService.upload(new Media[] {image});
// Display the results.
if (result != null && result.Length > 0) {
Media newImage = result[0];
Dictionary<MediaSize, Dimensions> dimensions =
CreateMediaDimensionMap(newImage.dimensions);
Console.WriteLine("Image with id '{0}', dimensions '{1}x{2}', and MIME type '{3}'" +
" was uploaded.", newImage.mediaId, dimensions[MediaSize.FULL].width,
dimensions[MediaSize.FULL].height, newImage.mimeType);
} else {
Console.WriteLine("No images were uploaded.");
}
} catch (Exception ex) {
throw new System.ApplicationException("Failed to upload image.", ex);
}
}