Пример #1
0
    private static void createSiteLinksFeed(
      AdWordsUser user, SiteLinksDataHolder siteLinksData) {
      // Get the FeedService.
      FeedService feedService = (FeedService) user.GetService(AdWordsService.v201406.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 new Feed for ad customizers.
    /// </summary>
    /// <param name="user">The AdWords user.</param>
    /// <returns>A new CustomizersDataHolder, populated with the feed ID and
    /// attribute IDs of the new Feed.</returns>
    private static CustomizersDataHolder CreateCustomizerFeed(AdWordsUser user) {
      // Get the FeedService.
      FeedService feedService = (FeedService) user.GetService(AdWordsService.v201406.FeedService);

      Feed customizerFeed = new Feed();
      customizerFeed.name = "CustomizerFeed";

      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;
    }