/// <summary>Snippet for GetMediaFile</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetMediaFile()
 {
     // Create client
     MediaFileServiceClient mediaFileServiceClient = MediaFileServiceClient.Create();
     // Initialize request argument(s)
     string resourceName = "customers/[CUSTOMER_ID]/mediaFiles/[MEDIA_FILE_ID]";
     // Make the request
     MediaFile response = mediaFileServiceClient.GetMediaFile(resourceName);
 }
 /// <summary>Snippet for GetMediaFile</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetMediaFileResourceNames()
 {
     // Create client
     MediaFileServiceClient mediaFileServiceClient = MediaFileServiceClient.Create();
     // Initialize request argument(s)
     MediaFileName resourceName = MediaFileName.FromCustomerMediaFile("[CUSTOMER]", "[MEDIA_FILE]");
     // Make the request
     MediaFile response = mediaFileServiceClient.GetMediaFile(resourceName);
 }
Exemplo n.º 3
0
        /// <summary>Snippet for GetMediaFileAsync</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public async Task GetMediaFileAsync()
        {
            // Create client
            MediaFileServiceClient mediaFileServiceClient = await MediaFileServiceClient.CreateAsync();

            // Initialize request argument(s)
            string resourceName = "customers/[CUSTOMER]/mediaFiles/[MEDIA_FILE]";
            // Make the request
            MediaFile response = await mediaFileServiceClient.GetMediaFileAsync(resourceName);
        }
        /// <summary>Snippet for GetMediaFileAsync</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public async Task GetMediaFileResourceNamesAsync()
        {
            // Create client
            MediaFileServiceClient mediaFileServiceClient = await MediaFileServiceClient.CreateAsync();

            // Initialize request argument(s)
            MediaFileName resourceName = MediaFileName.FromCustomerMediaFile("[CUSTOMER]", "[MEDIA_FILE]");
            // Make the request
            MediaFile response = await mediaFileServiceClient.GetMediaFileAsync(resourceName);
        }
 /// <summary>Snippet for GetMediaFile</summary>
 public void GetMediaFile()
 {
     // Snippet: GetMediaFile(string, CallSettings)
     // Create client
     MediaFileServiceClient mediaFileServiceClient = MediaFileServiceClient.Create();
     // Initialize request argument(s)
     string resourceName = "customers/[CUSTOMER]/mediaFiles/[MEDIA_FILE]";
     // Make the request
     MediaFile response = mediaFileServiceClient.GetMediaFile(resourceName);
     // End snippet
 }
 /// <summary>Snippet for GetMediaFile</summary>
 public void GetMediaFileResourceNames()
 {
     // Snippet: GetMediaFile(MediaFileName, CallSettings)
     // Create client
     MediaFileServiceClient mediaFileServiceClient = MediaFileServiceClient.Create();
     // Initialize request argument(s)
     MediaFileName resourceName = MediaFileName.FromCustomerMediaFile("[CUSTOMER_ID]", "[MEDIA_FILE_ID]");
     // Make the request
     MediaFile response = mediaFileServiceClient.GetMediaFile(resourceName);
     // End snippet
 }
 /// <summary>Snippet for GetMediaFile</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetMediaFileRequestObject()
 {
     // Create client
     MediaFileServiceClient mediaFileServiceClient = MediaFileServiceClient.Create();
     // Initialize request argument(s)
     GetMediaFileRequest request = new GetMediaFileRequest
     {
         ResourceNameAsMediaFileName = MediaFileName.FromCustomerMediaFile("[CUSTOMER_ID]", "[MEDIA_FILE_ID]"),
     };
     // Make the request
     MediaFile response = mediaFileServiceClient.GetMediaFile(request);
 }
Exemplo n.º 8
0
 /// <summary>Snippet for MutateMediaFiles</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void MutateMediaFiles()
 {
     // Create client
     MediaFileServiceClient mediaFileServiceClient = MediaFileServiceClient.Create();
     // Initialize request argument(s)
     string customerId = "";
     IEnumerable <MediaFileOperation> operations = new MediaFileOperation[]
     {
         new MediaFileOperation(),
     };
     // Make the request
     MutateMediaFilesResponse response = mediaFileServiceClient.MutateMediaFiles(customerId, operations);
 }
        /// <summary>Snippet for GetMediaFileAsync</summary>
        public async Task GetMediaFileAsync()
        {
            // Snippet: GetMediaFileAsync(string, CallSettings)
            // Additional: GetMediaFileAsync(string, CancellationToken)
            // Create client
            MediaFileServiceClient mediaFileServiceClient = await MediaFileServiceClient.CreateAsync();

            // Initialize request argument(s)
            string resourceName = "customers/[CUSTOMER_ID]/mediaFiles/[MEDIA_FILE_ID]";
            // Make the request
            MediaFile response = await mediaFileServiceClient.GetMediaFileAsync(resourceName);

            // End snippet
        }
        /// <summary>Snippet for GetMediaFileAsync</summary>
        public async Task GetMediaFileResourceNamesAsync()
        {
            // Snippet: GetMediaFileAsync(MediaFileName, CallSettings)
            // Additional: GetMediaFileAsync(MediaFileName, CancellationToken)
            // Create client
            MediaFileServiceClient mediaFileServiceClient = await MediaFileServiceClient.CreateAsync();

            // Initialize request argument(s)
            MediaFileName resourceName = MediaFileName.FromCustomerMediaFile("[CUSTOMER_ID]", "[MEDIA_FILE_ID]");
            // Make the request
            MediaFile response = await mediaFileServiceClient.GetMediaFileAsync(resourceName);

            // End snippet
        }
Exemplo n.º 11
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The customer ID for which the call is made.</param>
        public void Run(GoogleAdsClient client, long customerId)
        {
            // Get the MediaFileServiceClient.
            MediaFileServiceClient mediaFileService = client.GetService(
                Services.V10.MediaFileService);

            // Creates an HTML5 zip file media bundle content.
            byte[] bundleContent = MediaUtilities.GetAssetDataFromUrl(BUNDLE_URL, client.Config);

            // Creates a media file.
            MediaFile mediaFile = new MediaFile()
            {
                Name        = "Ad Media Bundle",
                Type        = MediaType.MediaBundle,
                MediaBundle = new MediaBundle()
                {
                    Data = ByteString.CopyFrom(bundleContent),
                }
            };

            // Creates a media file operation.
            MediaFileOperation operation = new MediaFileOperation()
            {
                Create = mediaFile
            };

            try
            {
                // Issues a mutate request to add the media file.
                MutateMediaFilesResponse response =
                    mediaFileService.MutateMediaFiles(customerId.ToString(), new[] { operation });

                // Displays the result.
                Console.WriteLine($"The media bundle with resource name " +
                                  $"'{response.Results.First().ResourceName}' is created.");
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
                throw;
            }
        }
Exemplo n.º 12
0
 /// <summary>Snippet for MutateMediaFiles</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void MutateMediaFilesRequestObject()
 {
     // Create client
     MediaFileServiceClient mediaFileServiceClient = MediaFileServiceClient.Create();
     // Initialize request argument(s)
     MutateMediaFilesRequest request = new MutateMediaFilesRequest
     {
         CustomerId = "",
         Operations =
         {
             new MediaFileOperation(),
         },
         PartialFailure = false,
         ValidateOnly   = false,
     };
     // Make the request
     MutateMediaFilesResponse response = mediaFileServiceClient.MutateMediaFiles(request);
 }
        /// <summary>Snippet for MutateMediaFilesAsync</summary>
        public async Task MutateMediaFilesAsync()
        {
            // Snippet: MutateMediaFilesAsync(string, IEnumerable<MediaFileOperation>, CallSettings)
            // Additional: MutateMediaFilesAsync(string, IEnumerable<MediaFileOperation>, CancellationToken)
            // Create client
            MediaFileServiceClient mediaFileServiceClient = await MediaFileServiceClient.CreateAsync();

            // Initialize request argument(s)
            string customerId = "";
            IEnumerable <MediaFileOperation> operations = new MediaFileOperation[]
            {
                new MediaFileOperation(),
            };
            // Make the request
            MutateMediaFilesResponse response = await mediaFileServiceClient.MutateMediaFilesAsync(customerId, operations);

            // End snippet
        }
Exemplo n.º 14
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The customer ID for which the call is made.</param>
        public void Run(GoogleAdsClient client, long customerId)
        {
            // Get the MediaFileServiceClient.
            MediaFileServiceClient mediaFileService =
                client.GetService(Services.V10.MediaFileService);

            const string URL = "https://gaagl.page.link/Eit5";

            MediaFile file = new MediaFile()
            {
                Name      = "Ad Image",
                Type      = MediaType.Image,
                SourceUrl = URL,
                Image     = new MediaImage()
                {
                    Data = ByteString.CopyFrom(MediaUtilities.GetAssetDataFromUrl(
                                                   URL, client.Config))
                }
            };
            MediaFileOperation operation = new MediaFileOperation()
            {
                Create = file
            };

            try
            {
                MutateMediaFilesResponse response =
                    mediaFileService.MutateMediaFiles(customerId.ToString(), new[] { operation });
                Console.WriteLine($"Added {response.Results} images:");
                foreach (MutateMediaFileResult result in response.Results)
                {
                    Console.WriteLine(result.ResourceName);
                }
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
                throw;
            }
        }
        /// <summary>Snippet for MutateMediaFilesAsync</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public async Task MutateMediaFilesRequestObjectAsync()
        {
            // Create client
            MediaFileServiceClient mediaFileServiceClient = await MediaFileServiceClient.CreateAsync();

            // Initialize request argument(s)
            MutateMediaFilesRequest request = new MutateMediaFilesRequest
            {
                CustomerId = "",
                Operations =
                {
                    new MediaFileOperation(),
                },
                PartialFailure      = false,
                ValidateOnly        = false,
                ResponseContentType = ResponseContentTypeEnum.Types.ResponseContentType.Unspecified,
            };
            // Make the request
            MutateMediaFilesResponse response = await mediaFileServiceClient.MutateMediaFilesAsync(request);
        }
 /// <summary>Snippet for MutateMediaFiles</summary>
 public void MutateMediaFilesRequestObject()
 {
     // Snippet: MutateMediaFiles(MutateMediaFilesRequest, CallSettings)
     // Create client
     MediaFileServiceClient mediaFileServiceClient = MediaFileServiceClient.Create();
     // Initialize request argument(s)
     MutateMediaFilesRequest request = new MutateMediaFilesRequest
     {
         CustomerId = "",
         Operations =
         {
             new MediaFileOperation(),
         },
         PartialFailure      = false,
         ValidateOnly        = false,
         ResponseContentType = ResponseContentTypeEnum.Types.ResponseContentType.Unspecified,
     };
     // Make the request
     MutateMediaFilesResponse response = mediaFileServiceClient.MutateMediaFiles(request);
     // End snippet
 }
        /// <summary>Snippet for MutateMediaFilesAsync</summary>
        public async Task MutateMediaFilesRequestObjectAsync()
        {
            // Snippet: MutateMediaFilesAsync(MutateMediaFilesRequest, CallSettings)
            // Additional: MutateMediaFilesAsync(MutateMediaFilesRequest, CancellationToken)
            // Create client
            MediaFileServiceClient mediaFileServiceClient = await MediaFileServiceClient.CreateAsync();

            // Initialize request argument(s)
            MutateMediaFilesRequest request = new MutateMediaFilesRequest
            {
                CustomerId = "",
                Operations =
                {
                    new MediaFileOperation(),
                },
                PartialFailure = false,
                ValidateOnly   = false,
            };
            // Make the request
            MutateMediaFilesResponse response = await mediaFileServiceClient.MutateMediaFilesAsync(request);

            // End snippet
        }
Exemplo n.º 18
0
        /// <summary>
        /// Adds the media files.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The Google Ads customer ID for which the call is made.</param>
        /// <returns>A map with key as image name, and value as image bytes.</returns>
        private Dictionary <string, string> AddMediaFiles(GoogleAdsClient client, long customerId)
        {
            // Get the MediaFileService.
            MediaFileServiceClient mediaFileService =
                client.GetService(Services.V2.MediaFileService);

            // Creates a bytes array from the logo image data.
            byte[] logoImageData = MediaUtilities.GetAssetDataFromUrl(
                "https://goo.gl/mtt54n", client.Config);

            // Creates the logo image.
            MediaFile mediaFileLogo = new MediaFile()
            {
                Type  = MediaType.Image,
                Image = new MediaImage()
                {
                    Data = ByteString.CopyFrom(logoImageData)
                },
                MimeType = MimeType.ImagePng
            };

            // Creates the operation for the logo image.
            MediaFileOperation mediaFileLogoOperation = new MediaFileOperation()
            {
                Create = mediaFileLogo
            };

            // Creates a bytes array from the marketing image data.
            byte[] marketingImageData = MediaUtilities.GetAssetDataFromUrl(
                "https://goo.gl/3b9Wfh", client.Config);

            // Creates the marketing image.
            MediaFile mediaFileMarketing = new MediaFile()
            {
                Type  = MediaType.Image,
                Image = new MediaImage()
                {
                    Data = ByteString.CopyFrom(marketingImageData)
                },
                MimeType = MimeType.ImageJpeg
            };

            // Creates the operation for the marketing image.
            MediaFileOperation mediaFileMarketingOperation = new MediaFileOperation()
            {
                Create = mediaFileMarketing
            };

            // Adds the media files.
            MutateMediaFilesResponse response =
                mediaFileService.MutateMediaFiles(customerId.ToString(),
                                                  new[] { mediaFileLogoOperation, mediaFileMarketingOperation });

            // Display the results.
            foreach (MutateMediaFileResult result in response.Results)
            {
                Console.WriteLine($"Created media file with resource name " +
                                  $"'{result.ResourceName}'.");
            }

            return(new Dictionary <string, string>()
            {
                { "logoResourceName", response.Results[0].ResourceName },
                { "marketingImageResourceName", response.Results[1].ResourceName },
            });
        }