Some help in getting of SiteLinks

43 views
Skip to first unread message

assaf

unread,
Jan 10, 2015, 3:29:54 PM1/10/15
to adwor...@googlegroups.com
Hi,

I followed closely with the AddSiteLinks /UpdateSiteLinks examples but still have an issue fully implementing getting campaign site links.
1. FeedMappingServiceInterface - Create Map for each FeedMappingID and it's placeholder type.
2. FeedItemServiceInterface - Created a list of FeedItemID (called siteLinkItemIDs) that their feedMappingID is of placeholder type 1 (from the Map in #1)
3. CampaignFeedServiceInterface - got the Feed ID and matching Function. -> here I got stuck - not sure how to user the Matching function to
   get the actual site link details .

Is there any example for the "get" implementation? 

Help is greatly appreciated.

This is how far I got:

                           Function f = campaignFeed.getMatchingFunction(); // this is from campaignFeedService
       
           RequestContextOperand requestContextOperand = new RequestContextOperand();
           requestContextOperand.setContextType(RequestContextOperandContextType.FEED_ITEM_ID);

           Function feedItemFunction = new Function();
           feedItemFunction.setLhsOperand(new FunctionArgumentOperand[] {requestContextOperand});
           feedItemFunction.setOperator(FunctionOperator.IN);

           List<FunctionArgumentOperand> operands = new ArrayList<FunctionArgumentOperand>();
           for (long feedItemId : siteLinkItemIDs) {
             ConstantOperand constantOperand = new ConstantOperand();
             constantOperand.setLongValue(feedItemId);
             constantOperand.setType(ConstantOperandConstantType.LONG);
             operands.add(constantOperand);
           }
           feedItemFunction.setRhsOperand(operands.toArray(new FunctionArgumentOperand[operands.size()])); 
                            FunctionOperand feedItemFunctionOperand = new FunctionOperand();
           feedItemFunctionOperand.setValue(feedItemFunction);

                            Function combinedFunction = new Function();
           combinedFunction.setOperator(FunctionOperator.AND);
           combinedFunction.setLhsOperand(
               new FunctionArgumentOperand[] {feedItemFunctionOperand});

           CampaignFeed campaignFeed2 = new CampaignFeed();
           campaignFeed2.setFeedId(feedId);
           campaignFeed2.setCampaignId(campaignId);
           campaignFeed2.setMatchingFunction(combinedFunction);
                            campaignFeed2.setPlaceholderTypes(new int[] {PLACEHOLDER_SITELINKS});

           CampaignFeedOperation operation = new CampaignFeedOperation();
           operation.setOperand(campaignFeed2);
           operation.setOperator(Operator.ADD);


Thanks for any help.

Assaf

Josh Radcliff (AdWords API Team)

unread,
Jan 12, 2015, 12:14:27 PM1/12/15
to adwor...@googlegroups.com
Hi Assaf,

You have two options for this:

1. If ads have served with the sitelinks, then you can use the PLACEHOLDER_FEED_ITEM_REPORT to see the feed item IDs of the sitelinks that have served with each campaign by including the FeedItemId and CampaignId fields in your report request, and filtering to rows where PlaceholderType is 1.

2. If ads have not served with the sitelinks, then you'll have to retrieve the CampaignFeed object using CampaignFeedService, and then inspect the matchingFunction of the returned object to extract the ConstantOperand objects containing the feed item IDs. This would look something like this in Java:

      Selector selector = new SelectorBuilder()
           .fields("CampaignId", "FeedId", "MatchingFunction", "PlaceholderTypes", "Status")
           .equals("CampaignId", "YOUR_CAMPAIGN_ID")
           .equals("Status", "ENABLED")
           .containsAll("PlaceholderTypes", "1")
           .build();
      // Use CampaignFeedService.get to retrieve the CampaignFeed using the above Selector.
      CampaignFeedServiceInterface campaignFeedService = adWordsServices.get(session, CampaignFeedServiceInterface.class);
      CampaignFeed campaignFeed = campaignFeedService.get(selector).getEntries()[0];

      // Inspect the matchingFunction to get the feed item IDs.
      Function matchingFunction = campaignFeed.getMatchingFunction();
      List<Long> feedItemIds = Lists.newArrayList();
      for (FunctionArgumentOperand operand : matchingFunction.getRhsOperand()) {
        ConstantOperand constantOperand = (ConstantOperand) operand;
        feedItemIds.add(constantOperand.getLongValue());
      }
      System.out.printf("Feed ID is %d, ids are: %s%n", campaignFeed.getFeedId(), feedItemIds);

Cheers,
Josh, AdWords API Team
Reply all
Reply to author
Forward
0 new messages