コード例 #1
0
    private static void createSiteLinksFeedMapping(
        AdWordsUser user, SiteLinksDataHolder siteLinksData) {
      // Get the FeedItemService.
      FeedMappingService feedMappingService =
        (FeedMappingService) user.GetService(AdWordsService.v201406.FeedMappingService);

      // Map the FeedAttributeIds to the fieldId constants.
      AttributeFieldMapping linkTextFieldMapping = new AttributeFieldMapping();
      linkTextFieldMapping.feedAttributeId = siteLinksData.LinkTextFeedAttributeId;
      linkTextFieldMapping.fieldId = PLACEHOLDER_FIELD_SITELINK_LINK_TEXT;
      AttributeFieldMapping linkUrlFieldMapping = new AttributeFieldMapping();
      linkUrlFieldMapping.feedAttributeId = siteLinksData.LinkUrlFeedAttributeId;
      linkUrlFieldMapping.fieldId = PLACEHOLDER_FIELD_SITELINK_URL;

      // Create the FieldMapping and operation.
      FeedMapping feedMapping = new FeedMapping();
      feedMapping.placeholderType = PLACEHOLDER_SITELINKS;
      feedMapping.feedId = siteLinksData.SiteLinksFeedId;
      feedMapping.attributeFieldMappings =
          new AttributeFieldMapping[] {linkTextFieldMapping, linkUrlFieldMapping};
      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);
      }
    }
コード例 #2
0
    /// <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);
    }