/// <summary> /// Gets the customer user access given an email address. /// </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="emailAddress">Email address of the user whose access role should be /// retrieved.</param> /// <returns>The user ID if a customer is found, or null if no matching customers were /// found.</returns> private long?GetUserAccess(GoogleAdsClient client, long customerId, string emailAddress) { // Get the GoogleAdsService. GoogleAdsServiceClient googleAdsService = client.GetService( Services.V6.GoogleAdsService); // Create the search query. Use the LIKE query for filtering to ignore the text case // for email address when searching for a match. string searchQuery = "Select customer_user_access.user_id, " + "customer_user_access.email_address, customer_user_access.access_role," + "customer_user_access.access_creation_date_time from customer_user_access " + $"where customer_user_access.email_address LIKE '{emailAddress}'"; // Retrieves the user accesses. PagedEnumerable <SearchGoogleAdsResponse, GoogleAdsRow> searchPagedResponse = googleAdsService.Search(customerId.ToString(), searchQuery); GoogleAdsRow result = searchPagedResponse.FirstOrDefault(); // Displays the results. if (result != null) { CustomerUserAccess access = result.CustomerUserAccess; Console.WriteLine("Customer user access with User ID = {0}, Email Address = " + "{1}, Access Role = {2} and Creation Time = {3} was found in " + "Customer ID: {4}.", access.UserId, access.EmailAddress, access.AccessRole, access.AccessCreationDateTime, customerId); return(access.UserId); } else { Console.WriteLine("No customer user access with requested email was found."); return(null); } }
/// <summary> /// Gets the Google My Business feed mapping. /// </summary> /// <param name="client">The Google Ads client.</param> /// <param name="customerId">The customer ID for which the call is made.</param> /// <param name="gmbFeedResourceName">The GMB feed resource name.</param> /// <returns>The newly created feed mapping.</returns> private static FeedMapping GetGMBFeedMapping(GoogleAdsClient client, long customerId, string gmbFeedResourceName) { // Get the GoogleAdsService. GoogleAdsServiceClient googleAdsService = client.GetService( Services.V3.GoogleAdsService); // Create the query. string query = $"SELECT feed_mapping.resource_name, feed_mapping.status FROM " + $"feed_mapping WHERE feed_mapping.feed = '{gmbFeedResourceName}' and " + $"feed_mapping.status = ENABLED and feed_mapping.placeholder_type = LOCATION" + $" LIMIT 1"; // Issue a search request. PagedEnumerable <SearchGoogleAdsResponse, GoogleAdsRow> result = googleAdsService.Search(customerId.ToString(), query); // Display the results. GoogleAdsRow googleAdsRow = result.FirstOrDefault(); return((googleAdsRow == null) ? null : googleAdsRow.FeedMapping); }