Get method not working in Data Service

50 views
Skip to first unread message

Yehoshaphat Schellekens

unread,
May 11, 2015, 1:01:42 AM5/11/15
to adwor...@googlegroups.com
HI All

I'm Trying to pull some data using the data service, i know that this service's get methods are a bit different, but im following the API in: https://developers.google.com/adwords/api/docs/reference/v201502/DataService

 It seems like my IDE doe's not recognize the other possible get methods, as following:

import com.google.api.ads.adwords.axis.factory.AdWordsServices;
import com.google.api.ads.adwords.axis.utils.v201502.SelectorBuilder;
import com.google.api.ads.adwords.axis.v201502.cm.AdGroupBidLandscapePage;
import com.google.api.ads.adwords.axis.v201502.cm.DataService;
import com.google.api.ads.adwords.axis.v201502.cm.Selector;
import com.google.api.ads.adwords.lib.client.AdWordsSession;
import com.google.api.ads.common.lib.auth.OfflineCredentials;
import com.google.api.client.auth.oauth2.Credential;

..........CREDENTIALS......

  public static void main(String[] args) throws Exception {
    // Generate a refreshable OAuth2 credential similar to a ClientLogin token
    // and can be used in place of a service account.
    Credential oAuth2Credential = new OfflineCredentials.Builder()
        .forApi(OfflineCredentials.Api.ADWORDS)
        .withClientSecrets(Client_ID, Client_secret).withRefreshToken(RefreshToken)
        .build()
        .generateCredential();

    // Construct an AdWordsSession.
    AdWordsSession session = new AdWordsSession.Builder()
        .withClientCustomerId(clientCustomerId).withDeveloperToken(developerToken).withUserAgent(userAgent)
        .withOAuth2Credential(oAuth2Credential)
        .build();

    AdWordsServices adWordsServices = new AdWordsServices();

    runExample(adWordsServices, session);
  }

  
  public static void runExample(
      AdWordsServices adWordsServices, AdWordsSession session) throws Exception {
    // Get the CampaignService.
    DataService dataService = adWordsServices.get(session, DataService.class);

    int offset = 0;

    // Create selector.
    SelectorBuilder builder = new SelectorBuilder();
    Selector selector = builder
        .fields("AdGroupId", "Bid", "CampaignId", "CriterionId", "EndDate", "LocalClicks", "LocalCost", "LocalImpressions", "PromotedImpressions", "StartDate")
        .build();

    AdGroupBidLandscapePage page = null;
    
    do {
      // Get all data
      page = dataService.getAdGroupBidLandscape(selector); // the problem is here : get method isn't  recognized
      
      
      // Display campaigns.
      if (page.getEntries() != null) {
        for ( DataService ds : page.getEntries()) { 
          System.out.println(ds.toString());
        }
      } else {
        System.out.println("No campaigns were found.");
      }

      offset += PAGE_SIZE;
      selector = builder.increaseOffsetBy(PAGE_SIZE).build();
    } while (offset < page.getTotalNumEntries());
  }




Thanks for any help on that :)

Josh Radcliff (AdWords API Team)

unread,
May 11, 2015, 2:00:47 PM5/11/15
to adwor...@googlegroups.com, yos...@gmail.com
Hi,

I think the problem here is that you are retrieving a DataService object from AdWordsServices. Please try switching to a DataServiceInterface object instead, as shown in the GetKeywordBidSimulations.java example, and let me know if that doesn't resolve the issue.

DataServiceInterface dataService = adWordsServices.get(session, DataServiceInterface.class);

Thanks,
Josh, AdWords API Team

Yehoshaphat Schellekens

unread,
May 12, 2015, 1:16:45 AM5/12/15
to adwor...@googlegroups.com, yos...@gmail.com
Thanks, it seems like its working :)
Reply all
Reply to author
Forward
0 new messages