/// <summary>Snippet for MutateFeeds</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public void MutateFeeds() { // Create client FeedServiceClient feedServiceClient = FeedServiceClient.Create(); // Initialize request argument(s) string customerId = ""; IEnumerable <FeedOperation> operations = new FeedOperation[] { new FeedOperation(), }; // Make the request MutateFeedsResponse response = feedServiceClient.MutateFeeds(customerId, operations); }
/// <summary> /// Removes the feeds. /// </summary> /// <param name="client">The Google Ads client.</param> /// <param name="customerId">The customer ID for which the call is made.</param> /// <param name="feeds">The list of feeds to remove.</param> private static void RemoveFeeds(GoogleAdsClient client, long customerId, Feed[] feeds) { List <FeedOperation> operations = new List <FeedOperation>(); foreach (Feed feed in feeds) { FeedOperation operation = new FeedOperation() { Remove = feed.ResourceName, }; operations.Add(operation); } FeedServiceClient feedService = client.GetService( Services.V5.FeedService); feedService.MutateFeeds(customerId.ToString(), operations.ToArray()); }
/// <summary> /// Creates the Affiliate Location Extension feed. /// </summary> /// <param name="client">The Google Ads client.</param> /// <param name="customerId">The customer ID for which the call is made.</param> /// <param name="chainId">The retail chain ID.</param> /// <returns>Resource name of the newly created Affiliate Location Extension feed.</returns> private static string CreateAffiliateLocationExtensionFeed(GoogleAdsClient client, long customerId, long chainId) { // Optional: Delete all existing location extension feeds. This is an optional step, // and is required for this code example to run correctly more than once. // 1. Google Ads only allows one location extension feed per email address. // 2. A Google Ads account cannot have a location extension feed and an affiliate // location extension feed at the same time. DeleteLocationExtensionFeeds(client, customerId); // Get the FeedServiceClient. FeedServiceClient feedService = client.GetService(Services.V5.FeedService); // Creates a feed that will sync to retail addresses for a given retail chain ID. // Do not add FeedAttributes to this object as Google Ads will add // them automatically because this will be a system generated feed. Feed feed = new Feed() { Name = "Affiliate Location Extension feed #" + ExampleUtilities.GetRandomString(), AffiliateLocationFeedData = new AffiliateLocationFeedData() { ChainIds = { chainId }, RelationshipType = AffiliateLocationFeedRelationshipType.GeneralRetailer }, // Since this feed's contents will be managed by Google, // you must set its origin to GOOGLE. Origin = FeedOrigin.Google }; FeedOperation operation = new FeedOperation() { Create = feed }; // Adds the feed. MutateFeedsResponse response = feedService.MutateFeeds(customerId.ToString(), new[] { operation }); // Displays the results. string feedResourceName = response.Results[0].ResourceName; Console.WriteLine($"Affliate location extension feed created with resource name: " + $"{feedResourceName}."); return(feedResourceName); }
/// <summary> /// Creates a feed to be used for ad customization. /// </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="feedName">Name of the feed.</param> /// <returns>The resource name of the newly created feed.</returns> private string CreateAdCustomizerFeed(GoogleAdsClient client, long customerId, string feedName) { // Get the FeedServiceClient. FeedServiceClient feedService = client.GetService(Services.V4.FeedService); // Creates three feed attributes: a name, a price and a date. The attribute names // are arbitrary choices and will be used as placeholders in the ad text fields. FeedAttribute nameAttribute = new FeedAttribute() { Name = "Name", Type = FeedAttributeType.String }; FeedAttribute priceAttribute = new FeedAttribute() { Name = "Price", Type = FeedAttributeType.String }; FeedAttribute dateAttribute = new FeedAttribute() { Name = "Date", Type = FeedAttributeType.DateTime }; Feed adCustomizerFeed = new Feed() { Name = feedName, Attributes = { nameAttribute, priceAttribute, dateAttribute } }; FeedOperation feedOperation = new FeedOperation() { Create = adCustomizerFeed }; MutateFeedsResponse response = feedService.MutateFeeds(customerId.ToString(), new[] { feedOperation }); string feedResourceName = response.Results[0].ResourceName; Console.WriteLine($"Added feed with resource name '{feedResourceName}'."); return(feedResourceName); }
/// <summary>Snippet for MutateFeeds</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public void MutateFeedsRequestObject() { // Create client FeedServiceClient feedServiceClient = FeedServiceClient.Create(); // Initialize request argument(s) MutateFeedsRequest request = new MutateFeedsRequest { CustomerId = "", Operations = { new FeedOperation(), }, PartialFailure = false, ValidateOnly = false, }; // Make the request MutateFeedsResponse response = feedServiceClient.MutateFeeds(request); }
/// <summary> /// Creates the feed. /// </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>The resource name of the newly created feed.</returns> private string CreateFeed(GoogleAdsClient client, long customerId) { // Get the FeedService. FeedServiceClient feedService = client.GetService(Services.V3.FeedService); // Create a URL attribute. FeedAttribute urlAttribute = new FeedAttribute() { Type = FeedAttributeType.UrlList, Name = "Page URL" }; // Create a label attribute. FeedAttribute labelAttribute = new FeedAttribute() { Type = FeedAttributeType.StringList, Name = "Label" }; // Create the feed. Feed feed = new Feed() { Name = "DSA Feed #" + ExampleUtilities.GetRandomString(), Attributes = { urlAttribute, labelAttribute } }; // Create the operation. FeedOperation operation = new FeedOperation() { Create = feed }; // Add the feed. MutateFeedsResponse response = feedService.MutateFeeds(customerId.ToString(), new[] { operation }); string feedResourceName = response.Results[0].ResourceName; // Display the result. Console.WriteLine($"Feed with resource name '{feedResourceName}' was created."); return(feedResourceName); }
/// <summary>Snippet for MutateFeeds</summary> public void MutateFeedsRequestObject() { // Snippet: MutateFeeds(MutateFeedsRequest, CallSettings) // Create client FeedServiceClient feedServiceClient = FeedServiceClient.Create(); // Initialize request argument(s) MutateFeedsRequest request = new MutateFeedsRequest { CustomerId = "", Operations = { new FeedOperation(), }, PartialFailure = false, ValidateOnly = false, ResponseContentType = ResponseContentTypeEnum.Types.ResponseContentType.Unspecified, }; // Make the request MutateFeedsResponse response = feedServiceClient.MutateFeeds(request); // End snippet }
/// <summary> /// Creates a feed, which acts as a table to store data. /// </summary> /// <param name="client">The Google Ads client.</param> /// <param name="customerId">The customer ID for which the call is made.</param> /// <returns>The newly created feed.</returns> private Feed CreateFeed(GoogleAdsClient client, long customerId) { FeedServiceClient feedServiceClient = client.GetService(Services.V4.FeedService); GoogleAdsServiceClient googleAdsService = client.GetService( Services.V4.GoogleAdsService); Feed feed = new Feed() { Name = $"Sitelinks Feed {ExampleUtilities.GetRandomString()}", Origin = FeedOriginEnum.Types.FeedOrigin.User, // Specify the column name and data type. This is just raw data at this point, and // not yet linked to any particular purpose. The names are used to help us remember // what they are intended for later. Attributes = { CreateFeedAttribute("Link Text", FeedAttributeType.String), CreateFeedAttribute("Link Final URL", FeedAttributeType.UrlList), CreateFeedAttribute("Line 1", FeedAttributeType.String), CreateFeedAttribute("Line 2", FeedAttributeType.String) } }; FeedOperation operation = new FeedOperation() { Create = feed }; MutateFeedsResponse response = feedServiceClient.MutateFeeds( customerId.ToString(), new[] { operation }); string feedResourceName = response.Results[0].ResourceName; Console.WriteLine($"Created feed with resource name '{feedResourceName}'."); // After we create the feed, we need to fetch it so we can determine the // attribute IDs, which will be required when populating feed items. return(googleAdsService.Search( customerId.ToString(), $"SELECT feed.attributes FROM feed WHERE feed.resource_name = '{feedResourceName}'" ).First().Feed); }
/// <summary> /// Creates the feed. /// </summary> /// <param name="client">The Google Ads client.</param> /// <param name="customerId">The Google Ads customer ID for which the real estate feed is /// added.</param> /// <returns>Resource name of the newly created feed.</returns> private string CreateFeed(GoogleAdsClient client, long customerId) { // Get the FeedService. FeedServiceClient feedService = client.GetService(Services.V3.FeedService); // Creates a Listing ID attribute. FeedAttribute listingIdAttribute = new FeedAttribute() { Type = FeedAttributeType.String, Name = "Listing ID" }; // Creates a Listing Name attribute. FeedAttribute listingNameAttribute = new FeedAttribute() { Type = FeedAttributeType.String, Name = "Listing Name" }; // Creates a Final URLs attribute. FeedAttribute finalUrlsAttribute = new FeedAttribute() { Type = FeedAttributeType.UrlList, Name = "Final URLs" }; // Creates an Image URL attribute FeedAttribute imageUrlAttribute = new FeedAttribute() { Type = FeedAttributeType.Url, Name = "Image URL" }; // Creates a Contextual Keywords attribute FeedAttribute contextualKeywordsAttribute = new FeedAttribute() { Type = FeedAttributeType.StringList, Name = "Contextual Keywords" }; // Creates the feed. Feed feed = new Feed() { Name = "Real Estate Feed #" + ExampleUtilities.GetRandomString(), Attributes = { listingIdAttribute, listingNameAttribute, finalUrlsAttribute, imageUrlAttribute, contextualKeywordsAttribute } }; // Creates the operation. FeedOperation operation = new FeedOperation() { Create = feed }; // Adds the feed. MutateFeedsResponse response = feedService.MutateFeeds(customerId.ToString(), new[] { operation }); string feedResourceName = response.Results[0].ResourceName; // Displays the result. Console.WriteLine($"Feed with resource name '{feedResourceName}' was created."); return(feedResourceName); }
/// <summary> /// Creates the feed. /// </summary> /// <param name="client">The Google Ads client.</param> /// <param name="customerId">The Google Ads customer ID for which the flights feed is /// added.</param> /// <returns>Resource name of the newly created feed.</returns> private string CreateFeed(GoogleAdsClient client, long customerId) { // Get the FeedService. FeedServiceClient feedService = client.GetService(Services.V5.FeedService); // Creates a Flight Description attribute. FeedAttribute flightDescriptionAttribute = new FeedAttribute() { Type = FeedAttributeType.String, Name = "Flight Description" }; // Creates a Destination ID attribute. FeedAttribute destinationIdAttribute = new FeedAttribute() { Type = FeedAttributeType.String, Name = "Destination ID" }; // Creates a Flight Price attribute. FeedAttribute flightPriceAttribute = new FeedAttribute() { Type = FeedAttributeType.String, Name = "Flight Price" }; // Creates a Flight Sale Price attribute. FeedAttribute flightSalesPriceAttribute = new FeedAttribute() { Type = FeedAttributeType.String, Name = "Flight Sale Price" }; // Creates a Final URLs attribute. FeedAttribute finalUrlsAttribute = new FeedAttribute() { Type = FeedAttributeType.UrlList, Name = "Final URLs" }; // Creates the feed. Feed feed = new Feed() { Name = "Flights Feed #" + ExampleUtilities.GetRandomString(), Attributes = { flightDescriptionAttribute, destinationIdAttribute, flightPriceAttribute, flightSalesPriceAttribute, finalUrlsAttribute } }; // Creates the operation. FeedOperation operation = new FeedOperation() { Create = feed }; // Adds the feed. MutateFeedsResponse response = feedService.MutateFeeds(customerId.ToString(), new[] { operation }); string feedResourceName = response.Results[0].ResourceName; // Displays the result. Console.WriteLine($"Feed with resource name '{feedResourceName}' was created."); return(feedResourceName); }
/// <summary> /// Creates the Google My Business feed. /// </summary> /// <param name="client">The Google Ads client.</param> /// <param name="customerId">The customer ID for which the call is made.</param> /// <param name="gmbEmailAddress">The Google My Business login email address.</param> /// <param name="businessAccountId">The Google My Business account ID.</param> /// <param name="gmbAccessToken">The OAuth2 access token for The Google My Business /// account.</param> /// <returns>ID of the newly created Google My Business feed.</returns> private static string CreateGMBFeed(GoogleAdsClient client, long customerId, string gmbEmailAddress, string businessAccountId, string gmbAccessToken) { // Optional: Delete all existing location extension feeds. This is an optional step, // and is required for this code example to run correctly more than once. // 1. Google Ads only allows one location extension feed per email address. // 2. A Google Ads account cannot have a location extension feed and an affiliate // location extension feed at the same time. DeleteLocationExtensionFeeds(client, customerId); // Get the FeedServiceClient. FeedServiceClient feedService = client.GetService(Services.V3.FeedService); // Creates a feed that will sync to the Google My Business account specified by // gmbEmailAddress. Do not add FeedAttributes to this object as Google Ads will add // them automatically because this will be a system generated feed. Feed gmbFeed = new Feed() { Name = "Google My Business feed #" + ExampleUtilities.GetRandomString(), PlacesLocationFeedData = new PlacesLocationFeedData() { EmailAddress = gmbEmailAddress, // If the EmailAddress is for a GMB manager instead of the GMB // account owner, then set BusinessAccountId to the Google+ Page ID of // a location for which the manager has access. This information is available // through the Google My Business API. See // https://developers.google.com/my-business/reference/rest/v4/accounts.locations#locationkey // for details. BusinessAccountId = string.IsNullOrEmpty(businessAccountId) ? null : businessAccountId, // Used to filter Google My Business listings by labels. If entries exist in // label_filters, only listings that have at least one of the labels set are // candidates to be synchronized into FeedItems. If no entries exist in // label_filters, then all listings are candidates for syncing. LabelFilters = { "Stores in New York" }, // Sets the authentication info to be able to connect Google Ads to the GMB // account. OauthInfo = new OAuthInfo() { HttpMethod = "GET", HttpRequestUrl = GOOGLE_ADS_SCOPE, HttpAuthorizationHeader = $"Bearer {gmbAccessToken}" }, }, // Since this feed's feed items will be managed by Google, // you must set its origin to GOOGLE. Origin = FeedOrigin.Google }; FeedOperation operation = new FeedOperation() { Create = gmbFeed }; // Adds the feed. MutateFeedsResponse response = feedService.MutateFeeds(customerId.ToString(), new[] { operation }); // Displays the results. string gmbFeedResourceName = response.Results[0].ResourceName; Console.WriteLine($"GMB feed created with resource name: {gmbFeedResourceName}."); return(gmbFeedResourceName); }