/// <summary> /// Creates the feed for DSA page URLs. /// </summary> /// <param name="user">The AdWords User.</param> /// <returns>The feed details.</returns> private static DSAFeedDetails CreateFeed(AdWordsUser user) { using (FeedService feedService = (FeedService)user.GetService(AdWordsService.v201802.FeedService)) { // Create attributes. FeedAttribute urlAttribute = new FeedAttribute { type = FeedAttributeType.URL_LIST, name = "Page URL" }; FeedAttribute labelAttribute = new FeedAttribute { type = FeedAttributeType.STRING_LIST, name = "Label" }; // Create the feed. Feed sitelinksFeed = new Feed { name = "DSA Feed " + ExampleUtilities.GetRandomString(), attributes = new FeedAttribute[] { urlAttribute, labelAttribute }, origin = FeedOrigin.USER }; // Create operation. FeedOperation operation = new FeedOperation { operand = sitelinksFeed, @operator = Operator.ADD }; try { // Add the feed. FeedReturnValue result = feedService.mutate(new FeedOperation[] { operation }); Feed savedFeed = result.value[0]; return(new DSAFeedDetails { feedId = savedFeed.id, urlAttributeId = savedFeed.attributes[0].id, labelAttributeId = savedFeed.attributes[1].id, }); } catch (Exception e) { throw new System.ApplicationException("Failed to create DSA feed.", e); } } }
private static void createSitelinksFeed(AdWordsUser user, SitelinksDataHolder sitelinksData, string feedName) { // Get the FeedService. FeedService feedService = (FeedService)user.GetService(AdWordsService.v201702.FeedService); // Create attributes. FeedAttribute textAttribute = new FeedAttribute(); textAttribute.type = FeedAttributeType.STRING; textAttribute.name = "Link Text"; FeedAttribute finalUrlAttribute = new FeedAttribute(); finalUrlAttribute.type = FeedAttributeType.URL_LIST; finalUrlAttribute.name = "Link Final URLs"; FeedAttribute line2Attribute = new FeedAttribute(); line2Attribute.type = FeedAttributeType.STRING; line2Attribute.name = "Line 2"; FeedAttribute line3Attribute = new FeedAttribute(); line3Attribute.type = FeedAttributeType.STRING; line3Attribute.name = "Line 3"; // Create the feed. Feed sitelinksFeed = new Feed(); sitelinksFeed.name = feedName; sitelinksFeed.attributes = new FeedAttribute[] { textAttribute, finalUrlAttribute, line2Attribute, line3Attribute }; sitelinksFeed.origin = FeedOrigin.USER; // Create operation. FeedOperation operation = new FeedOperation(); operation.operand = sitelinksFeed; operation.@operator = Operator.ADD; // Add the feed. FeedReturnValue result = feedService.mutate(new FeedOperation[] { operation }); Feed savedFeed = result.value[0]; sitelinksData.FeedId = savedFeed.id; FeedAttribute[] savedAttributes = savedFeed.attributes; sitelinksData.LinkTextFeedAttributeId = savedAttributes[0].id; sitelinksData.LinkFinalUrlFeedAttributeId = savedAttributes[1].id; sitelinksData.Line2FeedAttributeId = savedAttributes[2].id; sitelinksData.Line3FeedAttributeId = savedAttributes[3].id; Console.WriteLine("Feed with name {0} and ID {1} with linkTextAttributeId {2}, " + "linkFinalUrlAttributeId {3}, line2AttributeId {4} and line3AttributeId {5} " + "was created.", savedFeed.name, savedFeed.id, savedAttributes[0].id, savedAttributes[1].id, savedAttributes[2].id, savedAttributes[3].id); }
/// <summary> /// Create a feed that will sync to the Google My Business account /// specified by gmbEmailAddress. /// </summary> /// <param name="user">The user.</param> /// <param name="gmbEmailAddress">The GMB email address.</param> /// <param name="gmbAccessToken">The GMB access token.</param> /// <param name="businessAccountIdentifier">The GMB account identifier.</param> /// <returns>The newly created GMB feed.</returns> private static Feed CreateGmbFeed(AdWordsUser user, string gmbEmailAddress, string gmbAccessToken, string businessAccountIdentifier) { using (FeedService feedService = (FeedService)user.GetService( AdWordsService.v201710.FeedService)) { // Create a feed that will sync to the Google My Business account // specified by gmbEmailAddress. Do not add FeedAttributes to this object, // as AdWords will add them automatically because this will be a // system generated feed. Feed gmbFeed = new Feed(); gmbFeed.name = String.Format("Google My Business feed #{0}", ExampleUtilities.GetRandomString()); PlacesLocationFeedData feedData = new PlacesLocationFeedData(); feedData.emailAddress = gmbEmailAddress; feedData.businessAccountIdentifier = businessAccountIdentifier; // Optional: specify labels to filter Google My Business listings. If // specified, only listings that have any of the labels set are // synchronized into FeedItems. feedData.labelFilters = new string[] { "Stores in New York City" }; OAuthInfo oAuthInfo = new OAuthInfo(); oAuthInfo.httpMethod = "GET"; // Permissions for the AdWords API scope will also cover GMB. oAuthInfo.httpRequestUrl = user.Config.GetDefaultOAuth2Scope(); oAuthInfo.httpAuthorizationHeader = string.Format("Bearer {0}", gmbAccessToken); feedData.oAuthInfo = oAuthInfo; gmbFeed.systemFeedGenerationData = feedData; // Since this feed's feed items will be managed by AdWords, // you must set its origin to ADWORDS. gmbFeed.origin = FeedOrigin.ADWORDS; // Create an operation to add the feed. FeedOperation feedOperation = new FeedOperation(); feedOperation.operand = gmbFeed; feedOperation.@operator = Operator.ADD; try { // Add the feed. Since it is a system generated feed, AdWords will // automatically: // 1. Set up the FeedAttributes on the feed. // 2. Set up a FeedMapping that associates the FeedAttributes of the // feed with the placeholder fields of the LOCATION placeholder // type. FeedReturnValue addFeedResult = feedService.mutate( new FeedOperation[] { feedOperation }); Feed addedFeed = addFeedResult.value[0]; Console.WriteLine("Added GMB feed with ID {0}", addedFeed.id); return(addedFeed); } catch (Exception e) { throw new System.ApplicationException("Failed to create GMB feed.", e); } } }
/// <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> /// Creates a new Feed for ad customizers. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="feedName">Name of the feed to be created.</param> /// <returns>A new CustomizersDataHolder, populated with the feed ID and /// attribute IDs of the new Feed.</returns> private static CustomizersDataHolder CreateCustomizerFeed(AdWordsUser user, string feedName) { // Get the FeedService. FeedService feedService = (FeedService)user.GetService(AdWordsService.v201406.FeedService); Feed customizerFeed = new Feed(); customizerFeed.name = feedName; FeedAttribute nameAttribute = new FeedAttribute(); nameAttribute.name = "Name"; nameAttribute.type = FeedAttributeType.STRING; FeedAttribute priceAttribute = new FeedAttribute(); priceAttribute.name = "Price"; priceAttribute.type = FeedAttributeType.STRING; FeedAttribute dateAttribute = new FeedAttribute(); dateAttribute.name = "Date"; dateAttribute.type = FeedAttributeType.DATE_TIME; customizerFeed.attributes = new FeedAttribute[] { nameAttribute, priceAttribute, dateAttribute }; FeedOperation feedOperation = new FeedOperation(); feedOperation.operand = customizerFeed; feedOperation.@operator = (Operator.ADD); Feed addedFeed = feedService.mutate(new FeedOperation[] { feedOperation }).value[0]; CustomizersDataHolder dataHolder = new CustomizersDataHolder(); dataHolder.FeedId = addedFeed.id; dataHolder.NameFeedAttributeId = addedFeed.attributes[0].id; dataHolder.PriceFeedAttributeId = addedFeed.attributes[1].id; dataHolder.DateFeedAttributeId = addedFeed.attributes[2].id; Console.WriteLine("Feed with name '{0}' and ID {1} was added with:\n", addedFeed.name, dataHolder.FeedId); Console.WriteLine(" Name attribute ID {0}\n", dataHolder.NameFeedAttributeId); Console.WriteLine(" Price attribute ID {0}\n", dataHolder.PriceFeedAttributeId); Console.WriteLine(" Date attribute ID {0}\n", dataHolder.DateFeedAttributeId); return(dataHolder); }
/// <summary>Snippet for MutateFeedsAsync</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 MutateFeedsAsync() { // Create client FeedServiceClient feedServiceClient = await FeedServiceClient.CreateAsync(); // Initialize request argument(s) string customerId = ""; IEnumerable <FeedOperation> operations = new FeedOperation[] { new FeedOperation(), }; // Make the request MutateFeedsResponse response = await feedServiceClient.MutateFeedsAsync(customerId, operations); }
/// <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> /// 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 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 MutateFeedsAsync</summary> public async Task MutateFeedsAsync() { // Snippet: MutateFeedsAsync(string, IEnumerable<FeedOperation>, CallSettings) // Additional: MutateFeedsAsync(string, IEnumerable<FeedOperation>, CancellationToken) // Create client FeedServiceClient feedServiceClient = await FeedServiceClient.CreateAsync(); // Initialize request argument(s) string customerId = ""; IEnumerable <FeedOperation> operations = new FeedOperation[] { new FeedOperation(), }; // Make the request MutateFeedsResponse response = await feedServiceClient.MutateFeedsAsync(customerId, operations); // End snippet }
/// <summary> /// Deletes the enabled GMB feeds. /// </summary> /// <param name="user">The AdWords user.</param> public void DeleteEnabledGmbFeeds(AdWordsUser user) { FeedService feedService = (FeedService)user.GetService(AdWordsService.v201806.FeedService); List <Feed> feedsToDelete = new List <Feed>(); string query = "Select Id, SystemFeedGenerationData, FeedStatus where FeedStatus=ENABLED"; FeedPage page = feedService.query(query); for (int i = 0; i < page.entries.Length; i++) { Feed f = page.entries[i]; PlacesLocationFeedData systemData = (f.systemFeedGenerationData as PlacesLocationFeedData); if (systemData != null) { feedsToDelete.Add(f); } } if (feedsToDelete.Count > 0) { List <FeedOperation> operations = new List <FeedOperation>(); for (int i = 0; i < feedsToDelete.Count; i++) { FeedOperation operation = new FeedOperation() { @operator = Operator.REMOVE, operand = new Feed() { id = feedsToDelete[i].id } }; operations.Add(operation); } feedService.mutate(operations.ToArray()); } return; }
/// <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); }
private static void createSiteLinksFeed( AdWordsUser user, SiteLinksDataHolder siteLinksData) { // Get the FeedService. FeedService feedService = (FeedService)user.GetService(AdWordsService.v201409.FeedService); // Create attributes. FeedAttribute textAttribute = new FeedAttribute(); textAttribute.type = FeedAttributeType.STRING; textAttribute.name = "Link Text"; FeedAttribute urlAttribute = new FeedAttribute(); urlAttribute.type = FeedAttributeType.URL; urlAttribute.name = "Link URL"; // Create the feed. Feed siteLinksFeed = new Feed(); siteLinksFeed.name = "Feed For Site Links"; siteLinksFeed.attributes = new FeedAttribute[] { textAttribute, urlAttribute }; siteLinksFeed.origin = FeedOrigin.USER; // Create operation. FeedOperation operation = new FeedOperation(); operation.operand = siteLinksFeed; operation.@operator = Operator.ADD; // Add the feed. FeedReturnValue result = feedService.mutate(new FeedOperation[] { operation }); Feed savedFeed = result.value[0]; siteLinksData.SiteLinksFeedId = savedFeed.id; FeedAttribute[] savedAttributes = savedFeed.attributes; siteLinksData.LinkTextFeedAttributeId = savedAttributes[0].id; siteLinksData.LinkUrlFeedAttributeId = savedAttributes[1].id; Console.WriteLine("Feed with name {0} and ID {1} with linkTextAttributeId {2}" + " and linkUrlAttributeId {3} was created.", savedFeed.name, savedFeed.id, savedAttributes[0].id, savedAttributes[1].id); }
/// <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 for DSA page URLs. /// </summary> /// <param name="user">The AdWords User.</param> /// <returns>The feed details.</returns> private static DSAFeedDetails CreateFeed(AdWordsUser user) { // Get the FeedService. FeedService feedService = (FeedService)user.GetService(AdWordsService.v201705.FeedService); // Create attributes. FeedAttribute urlAttribute = new FeedAttribute(); urlAttribute.type = FeedAttributeType.URL_LIST; urlAttribute.name = "Page URL"; FeedAttribute labelAttribute = new FeedAttribute(); labelAttribute.type = FeedAttributeType.STRING_LIST; labelAttribute.name = "Label"; // Create the feed. Feed sitelinksFeed = new Feed(); sitelinksFeed.name = "DSA Feed " + ExampleUtilities.GetRandomString(); sitelinksFeed.attributes = new FeedAttribute[] { urlAttribute, labelAttribute }; sitelinksFeed.origin = FeedOrigin.USER; // Create operation. FeedOperation operation = new FeedOperation(); operation.operand = sitelinksFeed; operation.@operator = Operator.ADD; // Add the feed. FeedReturnValue result = feedService.mutate(new FeedOperation[] { operation }); Feed savedFeed = result.value[0]; return(new DSAFeedDetails { feedId = savedFeed.id, urlAttributeId = savedFeed.attributes[0].id, labelAttributeId = savedFeed.attributes[1].id, }); }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="gmbEmailAddress">The email address for Google My Business /// account.</param> /// <param name="gmbAccessToken">The OAuth2 access token for Google /// My Business account.</param> /// <param name="businessAccountIdentifier">The account identifier for /// Google My Business account.</param> public void Run(AdWordsUser user, string gmbEmailAddress, string gmbAccessToken, string businessAccountIdentifier) { FeedService feedService = (FeedService) user.GetService(AdWordsService.v201601.FeedService); CustomerFeedService customerFeedService = (CustomerFeedService) user.GetService( AdWordsService.v201601.CustomerFeedService); // Create a feed that will sync to the Google My Business account // specified by gmbEmailAddress. Do not add FeedAttributes to this object, // as AdWords will add them automatically because this will be a // system generated feed. Feed gmbFeed = new Feed(); gmbFeed.name = String.Format("Google My Business feed #{0}", ExampleUtilities.GetRandomString()); PlacesLocationFeedData feedData = new PlacesLocationFeedData(); feedData.emailAddress = gmbEmailAddress; feedData.businessAccountIdentifier = businessAccountIdentifier; // Optional: specify labels to filter Google My Business listings. If // specified, only listings that have any of the labels set are // synchronized into FeedItems. feedData.labelFilters = new string[] { "Stores in New York City" }; OAuthInfo oAuthInfo = new OAuthInfo(); oAuthInfo.httpMethod = "GET"; // Permissions for the AdWords API scope will also cover GMB. oAuthInfo.httpRequestUrl = user.Config.GetDefaultOAuth2Scope(); oAuthInfo.httpAuthorizationHeader = string.Format("Bearer {0}", gmbAccessToken); feedData.oAuthInfo = oAuthInfo; gmbFeed.systemFeedGenerationData = feedData; // Since this feed's feed items will be managed by AdWords, // you must set its origin to ADWORDS. gmbFeed.origin = FeedOrigin.ADWORDS; // Create an operation to add the feed. FeedOperation feedOperation = new FeedOperation(); feedOperation.operand = gmbFeed; feedOperation.@operator = Operator.ADD; try { // Add the feed. Since it is a system generated feed, AdWords will // automatically: // 1. Set up the FeedAttributes on the feed. // 2. Set up a FeedMapping that associates the FeedAttributes of the // feed with the placeholder fields of the LOCATION placeholder // type. FeedReturnValue addFeedResult = feedService.mutate(new FeedOperation[] { feedOperation }); Feed addedFeed = addFeedResult.value[0]; Console.WriteLine("Added GMB feed with ID {0}", addedFeed.id); // Add a CustomerFeed that associates the feed with this customer for // the LOCATION placeholder type. CustomerFeed customerFeed = new CustomerFeed(); customerFeed.feedId = addedFeed.id; customerFeed.placeholderTypes = new int[] { PLACEHOLDER_LOCATION }; // Create a matching function that will always evaluate to true. Function customerMatchingFunction = new Function(); ConstantOperand constOperand = new ConstantOperand(); constOperand.type = ConstantOperandConstantType.BOOLEAN; constOperand.booleanValue = true; customerMatchingFunction.lhsOperand = new FunctionArgumentOperand[] { constOperand }; customerMatchingFunction.@operator = FunctionOperator.IDENTITY; customerFeed.matchingFunction = customerMatchingFunction; // Create an operation to add the customer feed. CustomerFeedOperation customerFeedOperation = new CustomerFeedOperation(); customerFeedOperation.operand = customerFeed; customerFeedOperation.@operator = Operator.ADD; // After the completion of the Feed ADD operation above the added feed // will not be available for usage in a CustomerFeed until the sync // between the AdWords and GMB accounts completes. The loop below // will retry adding the CustomerFeed up to ten times with an // exponential back-off policy. CustomerFeed addedCustomerFeed = null; AdWordsAppConfig config = new AdWordsAppConfig(); config.RetryCount = 10; ErrorHandler errorHandler = new ErrorHandler(config); do { try { CustomerFeedReturnValue customerFeedResult = customerFeedService.mutate(new CustomerFeedOperation[] { customerFeedOperation }); addedCustomerFeed = customerFeedResult.value[0]; Console.WriteLine("Added CustomerFeed for feed ID {0} and placeholder type {1}", addedCustomerFeed.feedId, addedCustomerFeed.placeholderTypes[0]); break; } catch (AdWordsApiException e) { ApiException apiException = (ApiException) e.ApiException; foreach (ApiError error in apiException.errors) { if (error is CustomerFeedError) { if ((error as CustomerFeedError).reason == CustomerFeedErrorReason.MISSING_FEEDMAPPING_FOR_PLACEHOLDER_TYPE) { errorHandler.DoExponentialBackoff(); errorHandler.IncrementRetriedAttempts(); } else { throw; } } } } } while (errorHandler.HaveMoreRetryAttemptsLeft()); // OPTIONAL: Create a CampaignFeed to specify which FeedItems to use at // the Campaign level. This will be similar to the CampaignFeed in the // AddSiteLinks example, except you can also filter based on the // business name and category of each FeedItem by using a // FeedAttributeOperand in your matching function. // OPTIONAL: Create an AdGroupFeed for even more fine grained control // over which feed items are used at the AdGroup level. } catch (Exception e) { throw new System.ApplicationException("Failed to create customer feed.", e); } }
/// <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> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="gmbEmailAddress">The email address for Google My Business /// account.</param> /// <param name="gmbAccessToken">The OAuth2 access token for Google /// My Business account.</param> /// <param name="businessAccountIdentifier">The account identifier for /// Google My Business account.</param> public void Run(AdWordsUser user, string gmbEmailAddress, string gmbAccessToken, string businessAccountIdentifier) { FeedService feedService = (FeedService)user.GetService(AdWordsService.v201502.FeedService); CustomerFeedService customerFeedService = (CustomerFeedService)user.GetService( AdWordsService.v201502.CustomerFeedService); // Create a feed that will sync to the Google My Business account // specified by gmbEmailAddress. Do not add FeedAttributes to this object, // as AdWords will add them automatically because this will be a // system generated feed. Feed gmbFeed = new Feed(); gmbFeed.name = String.Format("Google My Business feed #{0}", ExampleUtilities.GetRandomString()); PlacesLocationFeedData feedData = new PlacesLocationFeedData(); feedData.emailAddress = gmbEmailAddress; feedData.businessAccountIdentifier = businessAccountIdentifier; OAuthInfo oAuthInfo = new OAuthInfo(); oAuthInfo.httpMethod = "GET"; // Permissions for the AdWords API scope will also cover GMB. oAuthInfo.httpRequestUrl = user.Config.GetDefaultOAuth2Scope(); oAuthInfo.httpAuthorizationHeader = string.Format("Bearer {0}", gmbAccessToken); feedData.oAuthInfo = oAuthInfo; gmbFeed.systemFeedGenerationData = feedData; // Since this feed's feed items will be managed by AdWords, // you must set its origin to ADWORDS. gmbFeed.origin = FeedOrigin.ADWORDS; // Create an operation to add the feed. FeedOperation feedOperation = new FeedOperation(); feedOperation.operand = gmbFeed; feedOperation.@operator = Operator.ADD; try { // Add the feed. Since it is a system generated feed, AdWords will // automatically: // 1. Set up the FeedAttributes on the feed. // 2. Set up a FeedMapping that associates the FeedAttributes of the // feed with the placeholder fields of the LOCATION placeholder // type. FeedReturnValue addFeedResult = feedService.mutate(new FeedOperation[] { feedOperation }); Feed addedFeed = addFeedResult.value[0]; Console.WriteLine("Added GMB feed with ID {0}", addedFeed.id); // Add a CustomerFeed that associates the feed with this customer for // the LOCATION placeholder type. CustomerFeed customerFeed = new CustomerFeed(); customerFeed.feedId = addedFeed.id; customerFeed.placeholderTypes = new int[] { PLACEHOLDER_LOCATION }; // Create a matching function that will always evaluate to true. Function customerMatchingFunction = new Function(); ConstantOperand constOperand = new ConstantOperand(); constOperand.type = ConstantOperandConstantType.BOOLEAN; constOperand.booleanValue = true; customerMatchingFunction.lhsOperand = new FunctionArgumentOperand[] { constOperand }; customerMatchingFunction.@operator = FunctionOperator.IDENTITY; customerFeed.matchingFunction = customerMatchingFunction; // Create an operation to add the customer feed. CustomerFeedOperation customerFeedOperation = new CustomerFeedOperation(); customerFeedOperation.operand = customerFeed; customerFeedOperation.@operator = Operator.ADD; // After the completion of the Feed ADD operation above the added feed // will not be available for usage in a CustomerFeed until the sync // between the AdWords and GMB accounts completes. The loop below // will retry adding the CustomerFeed up to ten times with an // exponential back-off policy. CustomerFeed addedCustomerFeed = null; AdWordsAppConfig config = new AdWordsAppConfig(); config.RetryCount = 10; ErrorHandler errorHandler = new ErrorHandler(config); do { try { CustomerFeedReturnValue customerFeedResult = customerFeedService.mutate(new CustomerFeedOperation[] { customerFeedOperation }); addedCustomerFeed = customerFeedResult.value[0]; Console.WriteLine("Added CustomerFeed for feed ID {0} and placeholder type {1}", addedCustomerFeed.feedId, addedCustomerFeed.placeholderTypes[0]); break; } catch (AdWordsApiException e) { ApiException apiException = (ApiException)e.ApiException; foreach (ApiError error in apiException.errors) { if (error is CustomerFeedError) { if ((error as CustomerFeedError).reason == CustomerFeedErrorReason.MISSING_FEEDMAPPING_FOR_PLACEHOLDER_TYPE) { errorHandler.DoExponentialBackoff(); errorHandler.IncrementRetriedAttempts(); } else { throw; } } } } } while (errorHandler.HaveMoreRetryAttemptsLeft()); // OPTIONAL: Create a CampaignFeed to specify which FeedItems to use at // the Campaign level. This will be similar to the CampaignFeed in the // AddSiteLinks example, except you can also filter based on the // business name and category of each FeedItem by using a // FeedAttributeOperand in your matching function. // OPTIONAL: Create an AdGroupFeed for even more fine grained control // over which feed items are used at the AdGroup level. } catch (Exception e) { throw new System.ApplicationException("Failed to create customer feed.", e); } }
/// <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); }
private static void createSitelinksFeed(AdWordsUser user, SitelinksDataHolder sitelinksData, string feedName) { // Get the FeedService. FeedService feedService = (FeedService) user.GetService(AdWordsService.v201509.FeedService); // Create attributes. FeedAttribute textAttribute = new FeedAttribute(); textAttribute.type = FeedAttributeType.STRING; textAttribute.name = "Link Text"; FeedAttribute finalUrlAttribute = new FeedAttribute(); finalUrlAttribute.type = FeedAttributeType.URL_LIST; finalUrlAttribute.name = "Link URL"; // Create the feed. Feed sitelinksFeed = new Feed(); sitelinksFeed.name = feedName; sitelinksFeed.attributes = new FeedAttribute[] {textAttribute, finalUrlAttribute}; sitelinksFeed.origin = FeedOrigin.USER; // Create operation. FeedOperation operation = new FeedOperation(); operation.operand = sitelinksFeed; operation.@operator = Operator.ADD; // Add the feed. FeedReturnValue result = feedService.mutate(new FeedOperation[] {operation}); Feed savedFeed = result.value[0]; sitelinksData.FeedId = savedFeed.id; FeedAttribute[] savedAttributes = savedFeed.attributes; sitelinksData.LinkTextFeedAttributeId = savedAttributes[0].id; sitelinksData.LinkFinalUrlFeedAttributeId = savedAttributes[1].id; Console.WriteLine("Feed with name {0} and ID {1} with linkTextAttributeId {2}" + " and linkFinalUrlAttributeId {3} was created.", savedFeed.name, savedFeed.id, savedAttributes[0].id, savedAttributes[1].id); }