Пример #1
0
        /// <summary>
        /// Waits for the Affliate location extension feed to be ready.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The customer ID for which the call is made.</param>
        /// <param name="feedResourceName">Resource name of the feed.</param>
        private static FeedMapping WaitForFeedToBeReady(GoogleAdsClient client, long customerId,
                                                        string feedResourceName)
        {
            int numAttempts  = 0;
            int sleepSeconds = 0;

            while (numAttempts < MAX_FEEDMAPPING_RETRIEVAL_ATTEMPTS)
            {
                // Once you create a feed, Google's servers will setup the feed by creating feed
                // attributes and feed mapping. Once the feed mapping is created, it is ready to be
                // used for creating customer feed.
                // This process is asynchronous, so we wait until the feed mapping is created,
                // peforming exponential backoff.
                FeedMapping feedMapping = GetAffiliateLocationExtensionFeedMapping(
                    client, customerId, feedResourceName);

                if (feedMapping == null)
                {
                    numAttempts++;
                    sleepSeconds = (int)(5 * Math.Pow(2, numAttempts));
                    Console.WriteLine($"Checked: #{numAttempts} time(s). Feed is not ready " +
                                      $"yet. Waiting {sleepSeconds} seconds before trying again.");
                    Thread.Sleep(sleepSeconds * 1000);
                }
                else
                {
                    Console.WriteLine($"Feed {feedResourceName} is now ready.");
                    return(feedMapping);
                }
            }
            throw new RpcException(new Status(StatusCode.DeadlineExceeded,
                                              $"Feed is not ready after {MAX_FEEDMAPPING_RETRIEVAL_ATTEMPTS}" +
                                              $" retries."));
        }
Пример #2
0
        /// <summary>
        /// Creates the feed mapping for DSA page feeds.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="feedDetails">The feed details.</param>
        private static void CreateFeedMapping(AdWordsUser user, DSAFeedDetails feedDetails)
        {
            using (FeedMappingService feedMappingService =
                       (FeedMappingService)user.GetService(AdWordsService.v201802.FeedMappingService)) {
                // Map the FeedAttributeIds to the fieldId constants.
                AttributeFieldMapping urlFieldMapping = new AttributeFieldMapping();
                urlFieldMapping.feedAttributeId = feedDetails.urlAttributeId;
                urlFieldMapping.fieldId         = DSA_PAGE_URLS_FIELD_ID;

                AttributeFieldMapping labelFieldMapping = new AttributeFieldMapping();
                labelFieldMapping.feedAttributeId = feedDetails.labelAttributeId;
                labelFieldMapping.fieldId         = DSA_LABEL_FIELD_ID;

                // Create the FieldMapping and operation.
                FeedMapping feedMapping = new FeedMapping();
                feedMapping.criterionType          = DSA_PAGE_FEED_CRITERION_TYPE;
                feedMapping.feedId                 = feedDetails.feedId;
                feedMapping.attributeFieldMappings = new AttributeFieldMapping[] {
                    urlFieldMapping, labelFieldMapping
                };

                FeedMappingOperation operation = new FeedMappingOperation();
                operation.operand   = feedMapping;
                operation.@operator = Operator.ADD;

                try {
                    // Add the field mapping.
                    feedMappingService.mutate(new FeedMappingOperation[] { operation });
                    return;
                } catch (Exception e) {
                    throw new System.ApplicationException("Failed to create feed mapping.", e);
                }
            }
        }
 /// <summary>Snippet for GetFeedMapping</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetFeedMapping()
 {
     // Create client
     FeedMappingServiceClient feedMappingServiceClient = FeedMappingServiceClient.Create();
     // Initialize request argument(s)
     string resourceName = "customers/[CUSTOMER]/feedMappings/[FEED_MAPPING]";
     // Make the request
     FeedMapping response = feedMappingServiceClient.GetFeedMapping(resourceName);
 }
 /// <summary>Snippet for GetFeedMapping</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetFeedMappingResourceNames()
 {
     // Create client
     FeedMappingServiceClient feedMappingServiceClient = FeedMappingServiceClient.Create();
     // Initialize request argument(s)
     FeedMappingName resourceName = FeedMappingName.FromCustomerFeedMapping("[CUSTOMER]", "[FEED_MAPPING]");
     // Make the request
     FeedMapping response = feedMappingServiceClient.GetFeedMapping(resourceName);
 }
        /// <summary>Snippet for GetFeedMappingAsync</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 GetFeedMappingResourceNamesAsync()
        {
            // Create client
            FeedMappingServiceClient feedMappingServiceClient = await FeedMappingServiceClient.CreateAsync();

            // Initialize request argument(s)
            FeedMappingName resourceName = FeedMappingName.FromCustomerFeedFeedMapping("[CUSTOMER_ID]", "[FEED_ID]", "[FEED_MAPPING_ID]");
            // Make the request
            FeedMapping response = await feedMappingServiceClient.GetFeedMappingAsync(resourceName);
        }
        /// <summary>Snippet for GetFeedMappingAsync</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 GetFeedMappingAsync()
        {
            // Create client
            FeedMappingServiceClient feedMappingServiceClient = await FeedMappingServiceClient.CreateAsync();

            // Initialize request argument(s)
            string resourceName = "customers/[CUSTOMER]/feedMappings/[FEED_MAPPING]";
            // Make the request
            FeedMapping response = await feedMappingServiceClient.GetFeedMappingAsync(resourceName);
        }
Пример #7
0
        private static void createSitelinksFeedMapping(
            AdWordsUser user, SitelinksDataHolder sitelinksData)
        {
            // Get the FeedItemService.
            FeedMappingService feedMappingService =
                (FeedMappingService)user.GetService(AdWordsService.v201702.FeedMappingService);

            // Map the FeedAttributeIds to the fieldId constants.
            AttributeFieldMapping linkTextFieldMapping = new AttributeFieldMapping();

            linkTextFieldMapping.feedAttributeId = sitelinksData.LinkTextFeedAttributeId;
            linkTextFieldMapping.fieldId         = PLACEHOLDER_FIELD_SITELINK_LINK_TEXT;

            AttributeFieldMapping linkFinalUrlFieldMapping = new AttributeFieldMapping();

            linkFinalUrlFieldMapping.feedAttributeId = sitelinksData.LinkFinalUrlFeedAttributeId;
            linkFinalUrlFieldMapping.fieldId         = PLACEHOLDER_FIELD_SITELINK_FINAL_URL;

            AttributeFieldMapping line2FieldMapping = new AttributeFieldMapping();

            line2FieldMapping.feedAttributeId = sitelinksData.Line2FeedAttributeId;
            line2FieldMapping.fieldId         = PLACEHOLDER_FIELD_LINE_2_TEXT;

            AttributeFieldMapping line3FieldMapping = new AttributeFieldMapping();

            line3FieldMapping.feedAttributeId = sitelinksData.Line3FeedAttributeId;
            line3FieldMapping.fieldId         = PLACEHOLDER_FIELD_LINE_3_TEXT;

            // Create the FieldMapping and operation.
            FeedMapping feedMapping = new FeedMapping();

            feedMapping.placeholderType        = PLACEHOLDER_SITELINKS;
            feedMapping.feedId                 = sitelinksData.FeedId;
            feedMapping.attributeFieldMappings = new AttributeFieldMapping[] {
                linkTextFieldMapping, linkFinalUrlFieldMapping, line2FieldMapping, line3FieldMapping
            };

            FeedMappingOperation operation = new FeedMappingOperation();

            operation.operand   = feedMapping;
            operation.@operator = Operator.ADD;

            // Save the field mapping.
            FeedMappingReturnValue result =
                feedMappingService.mutate(new FeedMappingOperation[] { operation });

            foreach (FeedMapping savedFeedMapping in result.value)
            {
                Console.WriteLine(
                    "Feed mapping with ID {0} and placeholderType {1} was saved for feed with ID {2}.",
                    savedFeedMapping.feedMappingId, savedFeedMapping.placeholderType,
                    savedFeedMapping.feedId);
            }
        }
Пример #8
0
 /// <summary>Snippet for GetFeedMapping</summary>
 public void GetFeedMapping()
 {
     // Snippet: GetFeedMapping(string, CallSettings)
     // Create client
     FeedMappingServiceClient feedMappingServiceClient = FeedMappingServiceClient.Create();
     // Initialize request argument(s)
     string resourceName = "customers/[CUSTOMER_ID]/feedMappings/[FEED_ID]~[FEED_MAPPING_ID]";
     // Make the request
     FeedMapping response = feedMappingServiceClient.GetFeedMapping(resourceName);
     // End snippet
 }
Пример #9
0
 /// <summary>Snippet for GetFeedMapping</summary>
 public void GetFeedMappingResourceNames()
 {
     // Snippet: GetFeedMapping(FeedMappingName, CallSettings)
     // Create client
     FeedMappingServiceClient feedMappingServiceClient = FeedMappingServiceClient.Create();
     // Initialize request argument(s)
     FeedMappingName resourceName = FeedMappingName.FromCustomerFeedFeedMapping("[CUSTOMER_ID]", "[FEED_ID]", "[FEED_MAPPING_ID]");
     // Make the request
     FeedMapping response = feedMappingServiceClient.GetFeedMapping(resourceName);
     // End snippet
 }
Пример #10
0
 /// <summary>Snippet for GetFeedMapping</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetFeedMappingRequestObject()
 {
     // Create client
     FeedMappingServiceClient feedMappingServiceClient = FeedMappingServiceClient.Create();
     // Initialize request argument(s)
     GetFeedMappingRequest request = new GetFeedMappingRequest
     {
         ResourceNameAsFeedMappingName = FeedMappingName.FromCustomerFeedFeedMapping("[CUSTOMER_ID]", "[FEED_ID]", "[FEED_MAPPING_ID]"),
     };
     // Make the request
     FeedMapping response = feedMappingServiceClient.GetFeedMapping(request);
 }
Пример #11
0
 /// <summary>
 /// Gets the feed attribute ID for the retail chain Id.
 /// </summary>
 /// <param name="feedMapping">The feed mapping.</param>
 /// <returns>The feeed attribute ID.</returns>
 /// <exception cref="ArgumentException">Affiliate location feed mapping isn't setup
 /// correctly.</exception>
 public static long GetAttributeIdForChainId(FeedMapping feedMapping)
 {
     foreach (AttributeFieldMapping fieldMapping in feedMapping.AttributeFieldMappings)
     {
         if (fieldMapping.AffiliateLocationField ==
             AffiliateLocationPlaceholderField.ChainId)
         {
             return(fieldMapping.FeedAttributeId.Value);
         }
     }
     throw new ArgumentException("Affiliate location feed mapping isn't setup correctly.");
 }
        /// <summary>Snippet for GetFeedMappingAsync</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 GetFeedMappingRequestObjectAsync()
        {
            // Create client
            FeedMappingServiceClient feedMappingServiceClient = await FeedMappingServiceClient.CreateAsync();

            // Initialize request argument(s)
            GetFeedMappingRequest request = new GetFeedMappingRequest
            {
                ResourceNameAsFeedMappingName = FeedMappingName.FromCustomerFeedMapping("[CUSTOMER]", "[FEED_MAPPING]"),
            };
            // Make the request
            FeedMapping response = await feedMappingServiceClient.GetFeedMappingAsync(request);
        }
Пример #13
0
        /// <summary>Snippet for GetFeedMappingAsync</summary>
        public async Task GetFeedMappingAsync()
        {
            // Snippet: GetFeedMappingAsync(string, CallSettings)
            // Additional: GetFeedMappingAsync(string, CancellationToken)
            // Create client
            FeedMappingServiceClient feedMappingServiceClient = await FeedMappingServiceClient.CreateAsync();

            // Initialize request argument(s)
            string resourceName = "customers/[CUSTOMER_ID]/feedMappings/[FEED_ID]~[FEED_MAPPING_ID]";
            // Make the request
            FeedMapping response = await feedMappingServiceClient.GetFeedMappingAsync(resourceName);

            // End snippet
        }
Пример #14
0
        /// <summary>
        /// Creates a feed mapping, which tells Google Ads how to interpret this data to display
        /// additional sitelink information on ads.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The customer ID for which the call is made.</param>
        /// <param name="feed">The feed for which the operation will be created.</param>
        private void CreateFeedMapping(GoogleAdsClient client, long customerId, Feed feed)
        {
            FeedMappingServiceClient feedMappingServiceClient =
                client.GetService(Services.V4.FeedMappingService);

            FeedMapping feedMapping = new FeedMapping
            {
                PlaceholderType = PlaceholderTypeEnum.Types.PlaceholderType.Sitelink,
                Feed            = feed.ResourceName,
            };

            foreach (FeedAttribute feedAttribute in feed.Attributes)
            {
                AttributeFieldMapping attributeFieldMapping = new AttributeFieldMapping()
                {
                    FeedAttributeId = feedAttribute.Id
                };

                switch (feedAttribute.Name)
                {
                case "Link Text":
                    attributeFieldMapping.SitelinkField = SitelinkPlaceholderField.Text;
                    break;

                case "Link Final URL":
                    attributeFieldMapping.SitelinkField = SitelinkPlaceholderField.FinalUrls;
                    break;

                case "Line 1":
                    attributeFieldMapping.SitelinkField = SitelinkPlaceholderField.Line1;
                    break;

                case "Line 2":
                    attributeFieldMapping.SitelinkField = SitelinkPlaceholderField.Line2;
                    break;
                }

                feedMapping.AttributeFieldMappings.Add(attributeFieldMapping);
            }

            FeedMappingOperation operation = new FeedMappingOperation()
            {
                Create = feedMapping
            };

            MutateFeedMappingsResponse response = feedMappingServiceClient.MutateFeedMappings
                                                      (customerId.ToString(), new[] { operation });

            Console.WriteLine($"Created feed mapping '{response.Results.First().ResourceName}'");
        }
Пример #15
0
        /// <summary>Snippet for GetFeedMappingAsync</summary>
        public async Task GetFeedMappingResourceNamesAsync()
        {
            // Snippet: GetFeedMappingAsync(FeedMappingName, CallSettings)
            // Additional: GetFeedMappingAsync(FeedMappingName, CancellationToken)
            // Create client
            FeedMappingServiceClient feedMappingServiceClient = await FeedMappingServiceClient.CreateAsync();

            // Initialize request argument(s)
            FeedMappingName resourceName = FeedMappingName.FromCustomerFeedFeedMapping("[CUSTOMER_ID]", "[FEED_ID]", "[FEED_MAPPING_ID]");
            // Make the request
            FeedMapping response = await feedMappingServiceClient.GetFeedMappingAsync(resourceName);

            // End snippet
        }
Пример #16
0
        public static List <FeedMapping> GetFeedMappingByTableName(int feedProviderId, string tableName = null)
        {
            var lstFeedMapping  = new List <FeedMapping>();
            var lstSqlParameter = new List <SqlParameter>();

            lstSqlParameter.Add(new SqlParameter()
            {
                ParameterName = "@FeedProviderId", SqlDbType = SqlDbType.NVarChar, Value = feedProviderId
            });
            lstSqlParameter.Add(new SqlParameter()
            {
                ParameterName = "@TableName", SqlDbType = SqlDbType.NVarChar, Value = (object)tableName ?? DBNull.Value
            });

            var dt = DBProvider.GetDataTable("GetFeedMappingByTableName", CommandType.StoredProcedure, ref lstSqlParameter);

            if (dt != null && dt.Rows.Count > 0)
            {
                foreach (DataRow row in dt.Rows)
                {
                    var feedMapping = new FeedMapping()
                    {
                        Id           = Convert.ToInt32(row["Id"]),
                        FeedProvider = new FeedProvider()
                        {
                            Id = Convert.ToInt32(row["FeedProviderId"])
                        },
                        TableName         = Convert.ToString(row["TableName"]),
                        ColumnName        = Convert.ToString(row["ColumnName"]),
                        IsCustomFeedKey   = Convert.ToBoolean(row["IsCustomFeedKey"]),
                        FeedKey           = Convert.ToString(row["FeedKey"]),
                        FeedKeyPath       = Convert.ToString(row["FeedKeyPath"]),
                        ActualFeedKeyPath = Convert.ToString(row["ActualFeedKeyPath"]),
                        Constraint        = Convert.ToString(row["Constraint"]),
                        ColumnDataType    = Convert.ToString(row["ColumnDataType"])
                    };

                    if (row["ParentId"] != DBNull.Value)
                    {
                        feedMapping.ParentId = Convert.ToInt32(row["ParentId"]);
                    }

                    lstFeedMapping.Add(feedMapping);
                }
            }

            return(lstFeedMapping);
        }
Пример #17
0
        /// <summary>
        /// Creates a feed mapping for a given 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>
        /// <param name="feedResourceName">The feed resource for which feed mapping is created.
        /// </param>
        /// <param name="feedAttributes">The feed attributes.</param>
        private void CreateFeedMapping(GoogleAdsClient client, long customerId,
                                       string feedResourceName,
                                       Dictionary <DsaPageFeedCriterionField, FeedAttribute> feedAttributes
                                       )
        {
            // Get the FeedMappingService.
            FeedMappingServiceClient feedMappingService = client.GetService(
                Services.V3.FeedMappingService);

            FeedMapping feedMapping = new FeedMapping()
            {
                CriterionType = FeedMappingCriterionType.DsaPageFeed,
                Feed          = feedResourceName,

                // Map the FeedAttributeId to the fieldId constants.
                AttributeFieldMappings =
                {
                    new AttributeFieldMapping()
                    {
                        FeedAttributeId  = feedAttributes[DsaPageFeedCriterionField.PageUrl].Id,
                        DsaPageFeedField = DsaPageFeedCriterionField.PageUrl
                    },

                    new AttributeFieldMapping()
                    {
                        FeedAttributeId  = feedAttributes[DsaPageFeedCriterionField.Label].Id,
                        DsaPageFeedField = DsaPageFeedCriterionField.Label
                    }
                }
            };

            // Create the operation.
            FeedMappingOperation operation = new FeedMappingOperation()
            {
                Create = feedMapping
            };

            // Add the FeedMapping.
            MutateFeedMappingsResponse response =
                feedMappingService.MutateFeedMappings(customerId.ToString(), new[] { operation });

            // Display the results.
            foreach (MutateFeedMappingResult result in response.Results)
            {
                Console.WriteLine($"Created feed mapping with resource name" +
                                  $" '{result.ResourceName}'");
            }
        }
Пример #18
0
        /// <summary>
        /// Creates a feed mapping and sets the feed as an ad customizer 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>
        /// <param name="feedResourceName">The resource name of the feed.</param>
        /// <param name="feedAttributes">The attributes of the feed.</param>
        private void CreateAdCustomizerMapping(GoogleAdsClient client, long customerId,
                                               string feedResourceName, Dictionary <string, FeedAttribute> feedAttributes)
        {
            // Get the FeedMappingService.
            FeedMappingServiceClient feedMappingService =
                client.GetService(Services.V4.FeedMappingService);

            // Map the feed attributes to ad customizer placeholder fields.
            // For a full list of ad customizer placeholder fields, see
            // https://developers.google.com/google-ads/api/reference/rpc/latest/AdCustomizerPlaceholderFieldEnum.AdCustomizerPlaceholderField
            AttributeFieldMapping nameFieldMapping = new AttributeFieldMapping()
            {
                FeedAttributeId   = feedAttributes["Name"].Id,
                AdCustomizerField = AdCustomizerPlaceholderField.String
            };

            AttributeFieldMapping priceFieldMapping = new AttributeFieldMapping()
            {
                FeedAttributeId   = feedAttributes["Price"].Id,
                AdCustomizerField = AdCustomizerPlaceholderField.Price
            };

            AttributeFieldMapping dateFieldMapping = new AttributeFieldMapping()
            {
                FeedAttributeId   = feedAttributes["Date"].Id,
                AdCustomizerField = AdCustomizerPlaceholderField.Date
            };

            FeedMapping feedMapping = new FeedMapping()
            {
                Feed                   = feedResourceName,
                PlaceholderType        = PlaceholderType.AdCustomizer,
                AttributeFieldMappings = { nameFieldMapping, priceFieldMapping, dateFieldMapping }
            };

            FeedMappingOperation operation = new FeedMappingOperation()
            {
                Create = feedMapping
            };

            MutateFeedMappingsResponse response =
                feedMappingService.MutateFeedMappings(customerId.ToString(), new[] { operation });

            Console.WriteLine($"Added feed mapping with resource name" +
                              $" '{response.Results[0].ResourceName}'.");
        }
        /// <summary>Snippet for GetFeedMappingAsync</summary>
        public async Task GetFeedMappingRequestObjectAsync()
        {
            // Snippet: GetFeedMappingAsync(GetFeedMappingRequest, CallSettings)
            // Additional: GetFeedMappingAsync(GetFeedMappingRequest, CancellationToken)
            // Create client
            FeedMappingServiceClient feedMappingServiceClient = await FeedMappingServiceClient.CreateAsync();

            // Initialize request argument(s)
            GetFeedMappingRequest request = new GetFeedMappingRequest
            {
                ResourceNameAsFeedMappingName = FeedMappingName.FromCustomerFeedMapping("[CUSTOMER]", "[FEED_MAPPING]"),
            };
            // Make the request
            FeedMapping response = await feedMappingServiceClient.GetFeedMappingAsync(request);

            // End snippet
        }
Пример #20
0
        public static FeedMapping GetFeedMappingDetailByTableColumnName(string tableName, string columnName, int?feedProviderId = null)
        {
            FeedMapping feedMapping     = null;
            var         lstSqlParameter = new List <SqlParameter>();

            lstSqlParameter.Add(new SqlParameter()
            {
                ParameterName = "@FeedProviderId", SqlDbType = SqlDbType.Int, Value = (object)feedProviderId ?? DBNull.Value
            });
            lstSqlParameter.Add(new SqlParameter()
            {
                ParameterName = "@TableName", SqlDbType = SqlDbType.NVarChar, Value = tableName
            });
            lstSqlParameter.Add(new SqlParameter()
            {
                ParameterName = "@ColumnName", SqlDbType = SqlDbType.NVarChar, Value = columnName
            });

            var dt = DBProvider.GetDataTable("GetFeedMappingDetailByTableColumnName", CommandType.StoredProcedure, ref lstSqlParameter);

            if (dt != null && dt.Rows.Count > 0)
            {
                foreach (DataRow row in dt.Rows)
                {
                    feedMapping = new FeedMapping()
                    {
                        Id           = Convert.ToInt32(row["Id"]),
                        FeedProvider = new FeedProvider()
                        {
                            Id = Convert.ToInt32(row["FeedProviderId"])
                        },
                        TableName         = Convert.ToString(row["TableName"]),
                        ColumnName        = Convert.ToString(row["ColumnName"]),
                        IsCustomFeedKey   = Convert.ToBoolean(row["IsCustomFeedKey"]),
                        FeedKey           = Convert.ToString(row["FeedKey"]),
                        FeedKeyPath       = Convert.ToString(row["FeedKeyPath"]),
                        ActualFeedKeyPath = Convert.ToString(row["ActualFeedKeyPath"]),
                        Constraint        = Convert.ToString(row["Constraint"]),
                        Position          = row["Position"] != DBNull.Value ? Convert.ToInt32(row["Position"]) : (long?)null
                    };
                    break;
                }
            }
            return(feedMapping);
        }
        /// <summary>
        /// Creates a new FeedMapping that indicates how the data holder's feed
        /// should be interpreted in the context of ad customizers.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="dataHolder">The data holder that contains metadata about
        /// the customizer Feed.</param>
        private static void CreateFeedMapping(AdWordsUser user, CustomizersDataHolder dataHolder)
        {
            // Get the FeedMappingService.
            FeedMappingService feedMappingService = (FeedMappingService)user.GetService(
                AdWordsService.v201406.FeedMappingService);

            FeedMapping feedMapping = new FeedMapping();

            feedMapping.feedId          = dataHolder.FeedId;
            feedMapping.placeholderType = PLACEHOLDER_AD_CUSTOMIZER;

            List <AttributeFieldMapping> attributeFieldMappings = new List <AttributeFieldMapping>();
            AttributeFieldMapping        attributeFieldMapping;

            attributeFieldMapping = new AttributeFieldMapping();
            attributeFieldMapping.feedAttributeId = dataHolder.NameFeedAttributeId;
            attributeFieldMapping.fieldId         = PLACEHOLDER_FIELD_STRING;
            attributeFieldMappings.Add(attributeFieldMapping);

            attributeFieldMapping = new AttributeFieldMapping();
            attributeFieldMapping.feedAttributeId = dataHolder.PriceFeedAttributeId;
            attributeFieldMapping.fieldId         = PLACEHOLDER_FIELD_PRICE;
            attributeFieldMappings.Add(attributeFieldMapping);

            attributeFieldMapping = new AttributeFieldMapping();
            attributeFieldMapping.feedAttributeId = dataHolder.DateFeedAttributeId;
            attributeFieldMapping.fieldId         = PLACEHOLDER_FIELD_DATE;
            attributeFieldMappings.Add(attributeFieldMapping);

            feedMapping.attributeFieldMappings = attributeFieldMappings.ToArray();

            FeedMappingOperation feedMappingOperation = new FeedMappingOperation();

            feedMappingOperation.operand   = feedMapping;
            feedMappingOperation.@operator = Operator.ADD;

            FeedMapping addedFeedMapping =
                feedMappingService.mutate(new FeedMappingOperation[] { feedMappingOperation }).value[0];

            Console.WriteLine("Feed mapping with ID {0} and placeholder type {1} was added for " +
                              "feed with ID {2}.",
                              addedFeedMapping.feedMappingId, addedFeedMapping.placeholderType,
                              addedFeedMapping.feedId);
        }
Пример #22
0
        public async Task GetFeedMappingAsync2()
        {
            Mock <FeedMappingService.FeedMappingServiceClient> mockGrpcClient = new Mock <FeedMappingService.FeedMappingServiceClient>(MockBehavior.Strict);
            GetFeedMappingRequest request = new GetFeedMappingRequest
            {
                ResourceName = new FeedMappingName("[CUSTOMER]", "[FEED_MAPPING]").ToString(),
            };
            FeedMapping expectedResponse = new FeedMapping
            {
                ResourceName = "resourceName2625949903",
            };

            mockGrpcClient.Setup(x => x.GetFeedMappingAsync(request, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <FeedMapping>(Task.FromResult(expectedResponse), null, null, null, null));
            FeedMappingServiceClient client = new FeedMappingServiceClientImpl(mockGrpcClient.Object, null);
            FeedMapping response            = await client.GetFeedMappingAsync(request);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Пример #23
0
        public void GetFeedMapping2()
        {
            Mock <FeedMappingService.FeedMappingServiceClient> mockGrpcClient = new Mock <FeedMappingService.FeedMappingServiceClient>(MockBehavior.Strict);
            GetFeedMappingRequest request = new GetFeedMappingRequest
            {
                ResourceName = new FeedMappingName("[CUSTOMER]", "[FEED_MAPPING]").ToString(),
            };
            FeedMapping expectedResponse = new FeedMapping
            {
                ResourceName = "resourceName2625949903",
            };

            mockGrpcClient.Setup(x => x.GetFeedMapping(request, It.IsAny <CallOptions>()))
            .Returns(expectedResponse);
            FeedMappingServiceClient client = new FeedMappingServiceClientImpl(mockGrpcClient.Object, null);
            FeedMapping response            = client.GetFeedMapping(request);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Пример #24
0
        /// <summary>
        /// Creates the campaign 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="campaignId">The campaign ID for which the affiliate location extensions
        /// are added.</param>
        /// <param name="feedMapping">The affliate location extension feedmapping for
        /// <paramref name="feedResourceName"/></param>
        /// <param name="feedResourceName">The feed resource name.</param>
        /// <param name="chainId">The retail chain ID.</param>
        private static void CreateCampaignFeed(GoogleAdsClient client, long customerId,
                                               long campaignId, FeedMapping feedMapping, string feedResourceName, long chainId)
        {
            // Get the CampaignFeedService.
            CampaignFeedServiceClient campaignFeedService = client.GetService(
                Services.V5.CampaignFeedService);

            long   attributeIdForChainId = GetAttributeIdForChainId(feedMapping);
            string feedId = FeedName.Parse(feedResourceName).FeedId;

            string matchingFunction =
                $"IN(FeedAttribute[{feedId}, {attributeIdForChainId}], {chainId})";
            // Adds a CampaignFeed that associates the feed with this campaign for
            // the AFFILIATE_LOCATION placeholder type.
            CampaignFeed campaignFeed = new CampaignFeed()
            {
                Feed             = feedResourceName,
                PlaceholderTypes = { PlaceholderType.AffiliateLocation },
                MatchingFunction = new MatchingFunction()
                {
                    FunctionString = matchingFunction
                },
                Campaign = ResourceNames.Campaign(customerId, campaignId),
            };

            CampaignFeedOperation operation = new CampaignFeedOperation()
            {
                Create = campaignFeed
            };

            MutateCampaignFeedsResponse campaignFeedsResponse =
                campaignFeedService.MutateCampaignFeeds(
                    customerId.ToString(), new[] { operation });

            // Displays the result.
            string addedCampaignFeed = campaignFeedsResponse.Results[0].ResourceName;

            Console.WriteLine($"Campaign feed created with resource name: {addedCampaignFeed}.");
            return;
        }
Пример #25
0
        private static List <FeedMapping> processGetFeedMappingRows(DataTable dt, DataRow[] currentRows)
        {
            List <FeedMapping> lstFeedMapping = new List <FeedMapping>();

            foreach (DataRow row in currentRows)
            {
                var feedMapping = new FeedMapping()
                {
                    Id           = Convert.ToInt32(row["Id"]),
                    FeedProvider = new FeedProvider()
                    {
                        Id = Convert.ToInt32(row["FeedProviderId"])
                    },
                    TableName         = Convert.ToString(row["TableName"]),
                    ColumnName        = Convert.ToString(row["ColumnName"]),
                    IsCustomFeedKey   = Convert.ToBoolean(row["IsCustomFeedKey"]),
                    FeedKey           = Convert.ToString(row["FeedKey"]),
                    FeedKeyPath       = Convert.ToString(row["FeedKeyPath"]),
                    ActualFeedKeyPath = Convert.ToString(row["ActualFeedKeyPath"]),
                    Constraint        = Convert.ToString(row["Constraint"])
                };

                if (row["ParentId"] != DBNull.Value)
                {
                    feedMapping.ParentId = Convert.ToInt32(row["ParentId"]);
                }

                var rows = dt.Select("ParentId = " + feedMapping.Id, "Id");

                if (rows != null && rows.Length > 0)
                {
                    feedMapping.Childrens = processGetFeedMappingRows(dt, rows);
                }

                lstFeedMapping.Add(feedMapping);
            }

            return(lstFeedMapping);
        }
Пример #26
0
        public static FeedMapping GetFeedMappingDetail(long id)
        {
            FeedMapping feedMapping     = null;
            var         lstSqlParameter = new List <SqlParameter>();

            lstSqlParameter.Add(new SqlParameter()
            {
                ParameterName = "@id", SqlDbType = SqlDbType.BigInt, Value = id
            });

            var dt = DBProvider.GetDataTable("GetFeedMappingDetail", CommandType.StoredProcedure, ref lstSqlParameter);

            if (dt != null && dt.Rows.Count > 0)
            {
                foreach (DataRow row in dt.Rows)
                {
                    feedMapping = new FeedMapping()
                    {
                        Id           = Convert.ToInt32(row["Id"]),
                        FeedProvider = new FeedProvider()
                        {
                            Id = Convert.ToInt32(row["FeedProviderId"])
                        },
                        //FeedProviderId = Convert.ToInt32(row["FeedProviderId"]),
                        TableName         = Convert.ToString(row["TableName"]),
                        ColumnName        = Convert.ToString(row["ColumnName"]),
                        IsCustomFeedKey   = Convert.ToBoolean(row["IsCustomFeedKey"]),
                        FeedKey           = Convert.ToString(row["FeedKey"]),
                        FeedKeyPath       = Convert.ToString(row["FeedKeyPath"]),
                        ActualFeedKeyPath = Convert.ToString(row["ActualFeedKeyPath"]),
                        Constraint        = Convert.ToString(row["Constraint"])
                    };

                    break;
                }
            }

            return(feedMapping);
        }
Пример #27
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>
 /// <param name="chainId">The retail chain ID.</param>
 /// <param name="campaignId">The campaign ID for which the affiliate location extensions
 /// are added.</param>
 public void Run(GoogleAdsClient client, long customerId, long chainId, long campaignId)
 {
     try
     {
         string feedResourceName = CreateAffiliateLocationExtensionFeed(
             client, customerId, chainId);
         // After the completion of the feed creation operation above the added feed will not
         // be available for usage in a campaign feed until the feed mappings are created.
         // We will wait with an exponential back-off policy until the feed mappings have
         // been created.
         FeedMapping feedMapping = WaitForFeedToBeReady(client, customerId,
                                                        feedResourceName);
         CreateCampaignFeed(client, customerId, campaignId, feedMapping,
                            feedResourceName, chainId);
     }
     catch (GoogleAdsException e)
     {
         Console.WriteLine("Failure:");
         Console.WriteLine($"Message: {e.Message}");
         Console.WriteLine($"Failure: {e.Failure}");
         Console.WriteLine($"Request ID: {e.RequestId}");
         throw;
     }
 }
 public IntelligentFeedMapping()
 {
     FeedMapping = new FeedMapping();
 }
Пример #29
0
        /// <summary>
        /// Creates a feed mapping for a given 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>
        /// <param name="feedAttributes">The feed attributes.</param>
        /// <param name="feedResourceName">The resource name of the feed.</param>
        private void CreateFeedMapping(GoogleAdsClient client, long customerId,
                                       Dictionary <RealEstatePlaceholderField, FeedAttribute> feedAttributes,
                                       string feedResourceName)
        {
            // Get the FeedMappingServiceClient.
            FeedMappingServiceClient feedMappingService = client.GetService(
                Services.V3.FeedMappingService);

            // Maps the FeedAttributeIds to the placeholder values. The FeedAttributeId is the
            // ID of the FeedAttribute created in the CreatedFeed method. This can be thought of
            // as the generic ID of the column of the new feed. The placeholder value specifies
            // the type of column this is in the context of a real estate feed (e.g.
            // a LISTING_ID or LISTING_NAME). The FeedMapping associates the feed column by ID to
            // this type and controls how the feed attributes are presented in dynamic content.
            // See https://developers.google.com/google-ads/api/reference/rpc/Google.Ads.GoogleAds.V3.enums#Google.Ads.GoogleAds.V3.enums.RealEstatePlaceholderFieldEnum.RealEstatePlaceholderField
            // for the full list of placeholder values.

            AttributeFieldMapping listingIdMapping = new AttributeFieldMapping()
            {
                FeedAttributeId = feedAttributes[RealEstatePlaceholderField.ListingId].Id,
                RealEstateField = RealEstatePlaceholderField.ListingId
            };

            AttributeFieldMapping listingNameMapping = new AttributeFieldMapping()
            {
                FeedAttributeId = feedAttributes[RealEstatePlaceholderField.ListingName].Id,
                RealEstateField = RealEstatePlaceholderField.ListingName
            };

            AttributeFieldMapping finalUrlsMapping = new AttributeFieldMapping()
            {
                FeedAttributeId = feedAttributes[RealEstatePlaceholderField.FinalUrls].Id,
                RealEstateField = RealEstatePlaceholderField.FinalUrls
            };

            AttributeFieldMapping imageUrlMapping = new AttributeFieldMapping()
            {
                FeedAttributeId = feedAttributes[RealEstatePlaceholderField.ImageUrl].Id,
                RealEstateField = RealEstatePlaceholderField.ImageUrl
            };

            AttributeFieldMapping contextualKeywordsMapping = new AttributeFieldMapping()
            {
                FeedAttributeId = feedAttributes[RealEstatePlaceholderField.ContextualKeywords].Id,
                RealEstateField = RealEstatePlaceholderField.ContextualKeywords
            };

            // Creates the feed mapping.
            FeedMapping feedMapping = new FeedMapping()
            {
                PlaceholderType        = PlaceholderType.DynamicRealEstate,
                Feed                   = feedResourceName,
                AttributeFieldMappings =
                {
                    listingIdMapping,
                    listingNameMapping,
                    finalUrlsMapping,
                    imageUrlMapping,
                    contextualKeywordsMapping
                }
            };

            // Creates the operation.
            FeedMappingOperation operation = new FeedMappingOperation()
            {
                Create = feedMapping
            };

            // Adds the FeedMapping.
            MutateFeedMappingsResponse response = feedMappingService.MutateFeedMappings(
                customerId.ToString(), new[] { operation });

            // Displays the results.
            foreach (MutateFeedMappingResult result in response.Results)
            {
                Console.WriteLine($"Created feed mapping with resource name" +
                                  $" '{result.ResourceName}'.");
            }
        }
    private static void createSitelinksFeedMapping(
        AdWordsUser user, SitelinksDataHolder sitelinksData) {
      // Get the FeedItemService.
      FeedMappingService feedMappingService =
        (FeedMappingService) user.GetService(AdWordsService.v201509.FeedMappingService);

      // Map the FeedAttributeIds to the fieldId constants.
      AttributeFieldMapping linkTextFieldMapping = new AttributeFieldMapping();
      linkTextFieldMapping.feedAttributeId = sitelinksData.LinkTextFeedAttributeId;
      linkTextFieldMapping.fieldId = PLACEHOLDER_FIELD_SITELINK_LINK_TEXT;
      AttributeFieldMapping linkFinalUrlFieldMapping = new AttributeFieldMapping();
      linkFinalUrlFieldMapping.feedAttributeId = sitelinksData.LinkFinalUrlFeedAttributeId;
      linkFinalUrlFieldMapping.fieldId = PLACEHOLDER_FIELD_SITELINK_FINAL_URL;

      // Create the FieldMapping and operation.
      FeedMapping feedMapping = new FeedMapping();
      feedMapping.placeholderType = PLACEHOLDER_SITELINKS;
      feedMapping.feedId = sitelinksData.FeedId;
      feedMapping.attributeFieldMappings =
          new AttributeFieldMapping[] {linkTextFieldMapping, linkFinalUrlFieldMapping};
      FeedMappingOperation operation = new FeedMappingOperation();
      operation.operand = feedMapping;
      operation.@operator = Operator.ADD;

      // Save the field mapping.
      FeedMappingReturnValue result =
          feedMappingService.mutate(new FeedMappingOperation[] {operation});
      foreach (FeedMapping savedFeedMapping in result.value) {
        Console.WriteLine(
            "Feed mapping with ID {0} and placeholderType {1} was saved for feed with ID {2}.",
            savedFeedMapping.feedMappingId, savedFeedMapping.placeholderType,
            savedFeedMapping.feedId);
      }
    }
        /// <summary>
        /// Creates a feed mapping for a given 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>
        /// <param name="feedAttributes">The feed attributes.</param>
        /// <param name="feedResourceName">The resource name of the feed.</param>
        private void CreateFeedMapping(GoogleAdsClient client, long customerId,
                                       Dictionary <FlightPlaceholderField, FeedAttribute> feedAttributes,
                                       string feedResourceName)
        {
            // Get the FeedMappingServiceClient.
            FeedMappingServiceClient feedMappingService = client.GetService(
                Services.V5.FeedMappingService);

            // Maps the FeedAttributeIds to the fieldId constants.
            AttributeFieldMapping flightDescriptionMapping = new AttributeFieldMapping()
            {
                FeedAttributeId = feedAttributes[FlightPlaceholderField.FlightDescription].Id,
                FlightField     = FlightPlaceholderField.FlightDescription
            };

            AttributeFieldMapping destinationIdMapping = new AttributeFieldMapping()
            {
                FeedAttributeId = feedAttributes[FlightPlaceholderField.DestinationId].Id,
                FlightField     = FlightPlaceholderField.DestinationId
            };

            AttributeFieldMapping flightPriceMapping = new AttributeFieldMapping()
            {
                FeedAttributeId = feedAttributes[FlightPlaceholderField.FlightPrice].Id,
                FlightField     = FlightPlaceholderField.FlightPrice
            };

            AttributeFieldMapping flightSalePriceMapping = new AttributeFieldMapping()
            {
                FeedAttributeId = feedAttributes[FlightPlaceholderField.FlightSalePrice].Id,
                FlightField     = FlightPlaceholderField.FlightSalePrice
            };

            AttributeFieldMapping finalUrlsMapping = new AttributeFieldMapping()
            {
                FeedAttributeId = feedAttributes[FlightPlaceholderField.FinalUrls].Id,
                FlightField     = FlightPlaceholderField.FinalUrls
            };

            // Creates the feed mapping.
            FeedMapping feedMapping = new FeedMapping()
            {
                PlaceholderType        = PlaceholderType.DynamicFlight,
                Feed                   = feedResourceName,
                AttributeFieldMappings =
                {
                    flightDescriptionMapping,
                    destinationIdMapping,
                    flightPriceMapping,
                    flightSalePriceMapping,
                    finalUrlsMapping
                }
            };

            // Creates the operation.
            FeedMappingOperation operation = new FeedMappingOperation()
            {
                Create = feedMapping
            };

            // Adds the FeedMapping.
            MutateFeedMappingsResponse response = feedMappingService.MutateFeedMappings(
                customerId.ToString(), new[] { operation });

            // Displays the results.
            foreach (MutateFeedMappingResult result in response.Results)
            {
                Console.WriteLine($"Created feed mapping with resource name" +
                                  $" '{result.ResourceName}'.");
            }
        }