Hi Emiliano,

If I'm understanding your previous posts, you are trying to use the Java 
client library <https://github.com/googleads/googleads-java-lib> to 
retrieve the URLs of sitelinks for a specific campaign.

In order to do this, you'll have to navigate through a few different types 
of objects. Note that when performing *get* (or *query*) requests, you can 
find the list of selectable fields with the proper names on our Selector 
Fields page 
<https://developers.google.com/adwords/api/docs/appendix/selectorfields>.

   1. Use CampaignFeedService.get 
   
<https://developers.google.com/adwords/api/docs/reference/v201406/CampaignFeedService#get>
 to 
   fetch the CampaignFeed 
   
<https://developers.google.com/adwords/api/docs/reference/v201406/CampaignFeedService.CampaignFeed>
 object 
   for your campaign by filtering on *CampaignId* equal to your campaign 
   ID, *Status* equal to ENABLED, and *PlaceholderTypes 
   <https://developers.google.com/adwords/api/docs/appendix/placeholders> 
*equal 
   to 1. (Note: for simplicity's sake, I'm ignoring the *CampaignFeed*'s 
   matchingFunction 
   
<https://developers.google.com/adwords/api/docs/reference/v201406/CampaignFeedService.CampaignFeed#matchingFunction>,
 
   which may further limit the *FeedItem*s by *feedItemId*).
   2. Use FeedMappingService.get 
   
<https://developers.google.com/adwords/api/docs/reference/v201406/FeedMappingService#get>
 
   to fetch the *FeedMappings* for *PlaceholderType *1. Look through the 
   returned *FeedMappings* and their attributeFieldMapping 
   
<https://developers.google.com/adwords/api/docs/reference/v201406/FeedMappingService.AttributeFieldMapping>s
 
   to determine which attribute 
   
<https://developers.google.com/adwords/api/docs/reference/v201406/FeedService.FeedAttribute>
 
   of your *Feed* is mapped to field placeholder 2 (for URL 
   <https://developers.google.com/adwords/api/docs/appendix/placeholders>).
   3. Use FeedItemService.get 
   
<https://developers.google.com/adwords/api/docs/reference/v201406/FeedItemService#get>
 
   to retrieve all *FeedItems* for the *feedId* found in step 1. On each 
   *FeedItem* returned, Inspect the attribute identified in step 2 to get 
   the *URL* field value.

Below is a complete code sample I put together in Java. Please let me know 
if this does not cover your questions.

Cheers,
Josh, AdWords API Team

import com.google.api.ads.adwords.axis.factory.AdWordsServices;
import com.google.api.ads.adwords.axis.utils.v201406.SelectorBuilder;
import com.google.api.ads.adwords.axis.v201406.cm.AttributeFieldMapping;
import com.google.api.ads.adwords.axis.v201406.cm.CampaignFeed;
import 
com.google.api.ads.adwords.axis.v201406.cm.CampaignFeedServiceInterface;
import com.google.api.ads.adwords.axis.v201406.cm.FeedItem;
import com.google.api.ads.adwords.axis.v201406.cm.FeedItemAttributeValue;
import com.google.api.ads.adwords.axis.v201406.cm.FeedItemServiceInterface;
import com.google.api.ads.adwords.axis.v201406.cm.FeedMapping;
import 
com.google.api.ads.adwords.axis.v201406.cm.FeedMappingServiceInterface;
import com.google.api.ads.adwords.axis.v201406.cm.Selector;
import com.google.api.ads.adwords.lib.client.AdWordsSession;
import com.google.api.ads.common.lib.auth.OfflineCredentials;
import com.google.api.ads.common.lib.auth.OfflineCredentials.Api;
import com.google.api.client.auth.oauth2.Credential;

public class GetCampaignSiteLinks {

  public static void main(String[] args) throws Exception {
    Credential oAuth2Credential = new 
OfflineCredentials.Builder().forApi(Api.ADWORDS).fromFile()
        .build().generateCredential();

    // Construct an AdWordsSession.
    AdWordsSession session =
        new 
AdWordsSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();

    AdWordsServices adWordsServices = new AdWordsServices();

    Long campaignId = Long.valueOf("INSERT_CAMPAIGN_ID_HERE");
    
    getCampaignSitelinkUrls(campaignId, session, adWordsServices);
  }
  
  private static void getCampaignSitelinkUrls(Long campaignId, 
AdWordsSession session,
      AdWordsServices adWordsServices) throws Exception {
    // Find the ENABLED CampaignFeed that's mapped to the Campaign for 
sitelinks (placeholder type
    // of 1).
    CampaignFeedServiceInterface campaignFeedService = 
adWordsServices.get(session,
        CampaignFeedServiceInterface.class);
    Selector selector = new SelectorBuilder()
        .fields("CampaignId", "FeedId")
        .equals("PlaceholderTypes", "1")
        .equals("CampaignId", campaignId.toString())
        .equals("Status", "ENABLED")
        .build();
    CampaignFeed campaignFeed = 
campaignFeedService.get(selector).getEntries(0);
    
    // Find the ENABLED FeedMapping for the feed above.
    FeedMappingServiceInterface feedMappingService = 
adWordsServices.get(session,
        FeedMappingServiceInterface.class);
    selector = new SelectorBuilder()
        .fields("FeedId", "AttributeFieldMappings")
        .equals("PlaceholderType", "1")
        .equals("Status", "ENABLED")
        .equals("FeedId", campaignFeed.getFeedId().toString())
        .build();
    FeedMapping feedMapping = 
feedMappingService.get(selector).getEntries(0);
    
    // Find the attribute that's mapped to the URL placeholder field (2).
    AttributeFieldMapping urlAttributeFieldMapping = null;
    for(AttributeFieldMapping attributeFieldMapping : 
feedMapping.getAttributeFieldMappings()) {
      if(attributeFieldMapping.getFieldId().intValue() == 2) {
        urlAttributeFieldMapping = attributeFieldMapping;
        break;
      }
    }
    
    // Find the FeedItems on the feed and print each one's ID and URL
    FeedItemServiceInterface feedItemService =
        adWordsServices.get(session, FeedItemServiceInterface.class);
    selector = new SelectorBuilder()
        .fields("FeedId", "FeedItemId", "AttributeValues")
        .equals("FeedId", campaignFeed.getFeedId().toString())
        .build();
    
    for(FeedItem feedItem : feedItemService.get(selector).getEntries()) {
      // Get the FeedItemAttributeValue for the feed attribute ID 
identified above from
      // the FeedMapping.
      FeedItemAttributeValue urlAttributeValue = null;
      for(FeedItemAttributeValue attributeValue : 
feedItem.getAttributeValues()) {
        if (attributeValue.getFeedAttributeId().equals(
            urlAttributeFieldMapping.getFeedAttributeId())) {
          urlAttributeValue = attributeValue;
          break;
        }
      }
      System.out.printf("Feed item ID %d has URL %s.%n", 
feedItem.getFeedItemId(),
          urlAttributeValue.getStringValue());
    }
  }
}

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+:
https://googleadsdeveloper.blogspot.com/
https://plus.google.com/+GoogleAdsDevelopers/posts
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to adwords-api+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to