예제 #1
0
    private static FeedItemOperation newSiteLinkFeedItemAddOperation(
        SiteLinksDataHolder siteLinksData, String text, String url) {
      // Create the FeedItemAttributeValues for our text values.
      FeedItemAttributeValue linkTextAttributeValue = new FeedItemAttributeValue();
      linkTextAttributeValue.feedAttributeId = siteLinksData.LinkTextFeedAttributeId;
      linkTextAttributeValue.stringValue = text;
      FeedItemAttributeValue linkUrlAttributeValue = new FeedItemAttributeValue();
      linkUrlAttributeValue.feedAttributeId = siteLinksData.LinkUrlFeedAttributeId;
      linkUrlAttributeValue.stringValue = url;

      // Create the feed item and operation.
      FeedItem item = new FeedItem();
      item.feedId = siteLinksData.SiteLinksFeedId;
      item.attributeValues =
          new FeedItemAttributeValue[] {linkTextAttributeValue, linkUrlAttributeValue};
      FeedItemOperation operation = new FeedItemOperation();
      operation.operand = item;
      operation.@operator = Operator.ADD;
      return operation;
    }
예제 #2
0
    private static void createSiteLinksFeedItems(
        AdWordsUser user, SiteLinksDataHolder siteLinksData) {
      // Get the FeedItemService.
      FeedItemService feedItemService =
        (FeedItemService) user.GetService(AdWordsService.v201402.FeedItemService);

      // Create operations to add FeedItems.
      FeedItemOperation home =
          newSiteLinkFeedItemAddOperation(siteLinksData,
          "Home", "http://www.example.com");
      FeedItemOperation stores =
          newSiteLinkFeedItemAddOperation(siteLinksData,
          "Stores", "http://www.example.com/stores");
      FeedItemOperation onSale =
          newSiteLinkFeedItemAddOperation(siteLinksData,
          "On Sale", "http://www.example.com/sale");
      FeedItemOperation support =
          newSiteLinkFeedItemAddOperation(siteLinksData,
          "Support", "http://www.example.com/support");
      FeedItemOperation products =
          newSiteLinkFeedItemAddOperation(siteLinksData,
          "Products", "http://www.example.com/prods");
      FeedItemOperation aboutUs =
          newSiteLinkFeedItemAddOperation(siteLinksData,
          "About Us", "http://www.example.com/about");

      FeedItemOperation[] operations =
          new FeedItemOperation[] {home, stores, onSale, support, products, aboutUs};

      FeedItemReturnValue result = feedItemService.mutate(operations);
      foreach (FeedItem item in result.value) {
        Console.WriteLine("FeedItem with feedItemId {0} was added.", item.feedItemId);
        siteLinksData.SiteLinkFeedItemIds.Add(item.feedItemId);
      }
    }