/// <summary> /// Runs the code example. /// </summary> /// <param name="client">The Google Ads client.</param> /// <param name="customerId">The Google Ads customer ID for which the call is made.</param> /// <param name="artifactName">The artifact for which metadata is retrieved.</param> public void Run(GoogleAdsClient client, long customerId, string artifactName) { // Get the GoogleAdsFieldService. GoogleAdsFieldServiceClient googleAdsFieldService = client.GetService( Services.V4.GoogleAdsFieldService); // Create the query. string searchQuery = $"SELECT name, category, selectable, filterable, sortable, " + $"selectable_with, data_type, is_repeated WHERE name = '{artifactName}'"; try { // Search for an artifact whose name is the same as the specified artifactName. PagedEnumerable <SearchGoogleAdsFieldsResponse, GoogleAdsField> googleAdsFields = googleAdsFieldService.SearchGoogleAdsFields(searchQuery); if (googleAdsFields.Any()) { // Get all returned artifacts and print out their metadata. foreach (GoogleAdsField googleAdsField in googleAdsFields) { Console.WriteLine("An artifact named '{0}' with category '{1}' and " + "data type '{2}' {3} selectable, {4} filterable, {5} sortable " + "and {6} repeated.", googleAdsField.Name, googleAdsField.Category, googleAdsField.DataType, getIsOrIsNot(googleAdsField.Selectable), getIsOrIsNot(googleAdsField.Filterable), getIsOrIsNot(googleAdsField.Sortable), getIsOrIsNot(googleAdsField.IsRepeated)); List <string> selectableLists = new List <string>( googleAdsField.SelectableWith); selectableLists.Sort(); Console.WriteLine("The artifact can be selected with the following " + "artifacts:"); foreach (string item in selectableLists) { Console.WriteLine("- " + item); } } } else { Console.Error.WriteLine($"The specified artifact '{artifactName}' " + "doesn't exist."); } } 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 SearchGoogleAdsFields</summary> public void SearchGoogleAdsFields() { // Snippet: SearchGoogleAdsFields(string, string, int?, CallSettings) // Create client GoogleAdsFieldServiceClient googleAdsFieldServiceClient = GoogleAdsFieldServiceClient.Create(); // Initialize request argument(s) string query = ""; // Make the request PagedEnumerable <SearchGoogleAdsFieldsResponse, GoogleAdsField> response = googleAdsFieldServiceClient.SearchGoogleAdsFields(query); // Iterate over all response items, lazily performing RPCs as required foreach (GoogleAdsField item in response) { // Do something with each item Console.WriteLine(item); } // Or iterate over pages (of server-defined size), performing one RPC per page foreach (SearchGoogleAdsFieldsResponse page in response.AsRawResponses()) { // Do something with each page of items Console.WriteLine("A page of results:"); foreach (GoogleAdsField item in page) { // Do something with each item Console.WriteLine(item); } } // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required int pageSize = 10; Page <GoogleAdsField> singlePage = response.ReadPage(pageSize); // Do something with the page of items Console.WriteLine($"A page of {pageSize} results (unless it's the final page):"); foreach (GoogleAdsField item in singlePage) { // Do something with each item Console.WriteLine(item); } // Store the pageToken, for when the next page is required. string nextPageToken = singlePage.NextPageToken; // End snippet }