Ejemplo n.º 1
0
  public static void main(String[] args) {
    try {
      // Log SOAP XML request and response.
      AdWordsServiceLogger.log();

      // Get AdWordsUser from "~/adwords.properties".
      AdWordsUser user = new AdWordsUser();

      // Get the ExperimentService.
      ExperimentServiceInterface experimentService =
          user.getService(AdWordsService.V201109_1.EXPERIMENT_SERVICE);

      Long campaignId = Long.parseLong("INSET_CAMPAIGN_ID_HERE");

      // Create selector.
      Selector selector = new Selector();
      selector.setFields(
          new String[] {
            "Name", "Id", "ControlId", "AdGroupsCount", "AdGroupCriteriaCount", "AdGroupAdsCount"
          });
      selector.setOrdering(new OrderBy[] {new OrderBy("Name", SortOrder.ASCENDING)});

      // Create predicates.
      Predicate campaignIdPredicate =
          new Predicate("CampaignId", PredicateOperator.IN, new String[] {campaignId.toString()});
      selector.setPredicates(new Predicate[] {campaignIdPredicate});

      // Get all experiments.
      ExperimentPage page = experimentService.get(selector);

      if (page.getEntries() != null) {
        for (Experiment experiment : page.getEntries()) {
          System.out.println(
              "Experiment with name \""
                  + experiment.getName()
                  + "\", id \""
                  + experiment.getId()
                  + "\", and control id \""
                  + experiment.getControlId()
                  + "\" was found.\nIt includes "
                  + experiment.getExperimentSummaryStats().getAdGroupsCount()
                  + " ad groups, "
                  + experiment.getExperimentSummaryStats().getAdGroupCriteriaCount()
                  + " criteria, and "
                  + experiment.getExperimentSummaryStats().getAdGroupAdsCount()
                  + " ads.");
        }
      } else {
        System.out.println("No experiments were found.");
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 2
0
  public static void main(String[] args) {
    try {
      // Log SOAP XML request and response.
      AdWordsServiceLogger.log();

      // Get AdWordsUser from "~/adwords.properties".
      AdWordsUser user = new AdWordsUser();

      // Get the ConversionTrackerService.
      ConversionTrackerServiceInterface service =
          user.getService(AdWordsService.V201109_1.CONVERSION_TRACKER_SERVICE);

      // Create selector.
      Selector selector = new Selector();
      selector.setFields(new String[] {"Name", "Status", "Category"});
      selector.setOrdering(new OrderBy[] {new OrderBy("Name", SortOrder.ASCENDING)});

      // Get all conversions.
      ConversionTrackerPage page = service.get(selector);

      // Display conversions.
      if (page != null && page.getEntries() != null) {
        for (ConversionTracker conversionTracker : page.getEntries()) {
          if (conversionTracker instanceof AdWordsConversionTracker) {
            AdWordsConversionTracker newAdWordsConversionTracker =
                (AdWordsConversionTracker) conversionTracker;
            System.out.printf(
                "Conversion with id \"%d\", name \"%s\", status \"%s\", "
                    + "category \"%s\" and snippet \"%s\" was found.\n",
                newAdWordsConversionTracker.getId(),
                newAdWordsConversionTracker.getName(),
                newAdWordsConversionTracker.getStatus(),
                newAdWordsConversionTracker.getCategory(),
                newAdWordsConversionTracker.getSnippet());
          } else {
            System.out.printf(
                "Conversion with id \"%d\", name \"%s\", status \"%s\", "
                    + "category \"%s\" was found.\n",
                conversionTracker.getId(),
                conversionTracker.getName(),
                conversionTracker.getStatus(),
                conversionTracker.getCategory());
          }
        }
      } else {
        System.out.println("No conversions were found.");
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  public static void main(String[] args) {
    try {
      // Log SOAP XML request and response.
      AdWordsServiceLogger.log();

      // Get AdWordsUser from "~/adwords.properties".
      AdWordsUser user = new AdWordsUser();

      // Get the LocationCriterionService.
      LocationCriterionServiceInterface locationCriterionService =
          user.getService(AdWordsService.V201109.LOCATION_CRITERION_SERVICE);

      String[] locationNames = new String[] {"Paris", "Quebec", "Spain", "Deutschland"};
      Selector selector = new Selector();
      selector.setFields(
          new String[] {
            "Id", "LocationName", "CanonicalName", "DisplayType", "ParentLocations", "Reach"
          });

      selector.setPredicates(
          new Predicate[] {
            // Location names must match exactly, only EQUALS and IN are
            // supported.
            new Predicate("LocationName", PredicateOperator.IN, locationNames),
            // Set the locale of the returned location names.
            new Predicate("Locale", PredicateOperator.EQUALS, new String[] {"en"})
          });

      // Make the get request.
      LocationCriterion[] locationCriteria = locationCriterionService.get(selector);

      // Display the resulting location criteria.
      for (LocationCriterion locationCriterion : locationCriteria) {
        String parentString =
            getParentLocationString(locationCriterion.getLocation().getParentLocations());
        System.out.printf(
            "The search term '%s' returned the location '%s (%d)' of type '%s' "
                + "with parent locations '%s' and reach '%d'.\n",
            locationCriterion.getSearchTerm(),
            locationCriterion.getLocation().getLocationName(),
            locationCriterion.getLocation().getId(),
            locationCriterion.getLocation().getDisplayType(),
            parentString,
            locationCriterion.getReach());
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 4
0
  public static void main(String[] args) {
    try {
      // Log SOAP XML request and response.
      AdWordsServiceLogger.log();

      // Get AdWordsUser from "~/adwords.properties".
      AdWordsUser user = new AdWordsUser();

      // Get the InfoService.
      InfoServiceInterface infoService = user.getService(AdWordsService.V201109_1.INFO_SERVICE);

      // Create selector.
      InfoSelector selector = new InfoSelector();
      selector.setApiUsageType(ApiUsageType.OPERATION_COUNT);
      // From the start of the month until today.
      selector.setDateRange(
          new DateRange(
              new SimpleDateFormat("yyyyMM01").format(new Date()),
              new SimpleDateFormat("yyyyMMdd").format(new Date())));

      // Get api usage info.
      ApiUsageInfo apiUsageInfo = infoService.get(selector);

      // Display api usage info.
      if (apiUsageInfo != null) {
        System.out.println(
            "The total number of API operations performed this month is \""
                + apiUsageInfo.getCost()
                + "\".");
      } else {
        System.out.println("No api usage information was found.");
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 5
0
  public static void main(String[] args) {
    try {
      // Log SOAP XML request and response.
      AdWordsServiceLogger.log();

      // Get AdWordsUser from "~/adwords.properties".
      AdWordsUser user = new AdWordsUser();

      // Get the CampaignService.
      CampaignServiceInterface campaignService =
          user.getService(AdWordsService.V201109.CAMPAIGN_SERVICE);

      // Create campaign.
      Campaign campaign = new Campaign();
      campaign.setName("Interplanetary Cruise #" + System.currentTimeMillis());
      campaign.setStatus(CampaignStatus.PAUSED);
      campaign.setBiddingStrategy(new ManualCPC());

      // Create budget.
      Budget budget = new Budget();
      budget.setPeriod(BudgetBudgetPeriod.DAILY);
      budget.setAmount(new Money(null, 50000000L));
      budget.setDeliveryMethod(BudgetBudgetDeliveryMethod.STANDARD);
      campaign.setBudget(budget);

      // Set the campaign network options to Search and Search Network.
      NetworkSetting networkSetting = new NetworkSetting();
      networkSetting.setTargetGoogleSearch(true);
      networkSetting.setTargetSearchNetwork(true);
      networkSetting.setTargetContentNetwork(false);
      networkSetting.setTargetPartnerSearchNetwork(false);
      networkSetting.setTargetContentContextual(false);
      campaign.setNetworkSetting(networkSetting);

      // Create operations.
      CampaignOperation operation = new CampaignOperation();
      operation.setOperand(campaign);
      operation.setOperator(Operator.ADD);

      CampaignOperation[] operations = new CampaignOperation[] {operation};

      // Add campaign.
      CampaignReturnValue result = campaignService.mutate(operations);

      // Display campaigns.
      if (result != null && result.getValue() != null) {
        for (Campaign campaignResult : result.getValue()) {
          System.out.println(
              "Campaign with name \""
                  + campaignResult.getName()
                  + "\" and id \""
                  + campaignResult.getId()
                  + "\" was added.");
        }
      } else {
        System.out.println("No campaigns were added.");
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 6
0
  public static void main(String[] args) {
    try {
      // Log SOAP XML request and response.
      AdWordsServiceLogger.log();

      // Get AdWordsUser from "~/adwords.properties".
      AdWordsUser user = new AdWordsUser();

      // Get the TargetingIdeaService.
      TargetingIdeaServiceInterface targetingIdeaService =
          user.getService(AdWordsService.V201109.TARGETING_IDEA_SERVICE);

      // Create seed keyword.
      Keyword keyword = new Keyword();
      keyword.setText("mars cruise");
      keyword.setMatchType(KeywordMatchType.BROAD);

      // Create selector.
      TargetingIdeaSelector selector = new TargetingIdeaSelector();
      selector.setRequestType(RequestType.IDEAS);
      selector.setIdeaType(IdeaType.KEYWORD);
      selector.setRequestedAttributeTypes(
          new AttributeType[] {
            AttributeType.CRITERION, AttributeType.AVERAGE_TARGETED_MONTHLY_SEARCHES
          });

      // Set selector paging (required for targeting idea service).
      Paging paging = new Paging();
      paging.setStartIndex(0);
      paging.setNumberResults(10);
      selector.setPaging(paging);

      // Create related to keyword search parameter.
      RelatedToKeywordSearchParameter relatedToKeywordSearchParameter =
          new RelatedToKeywordSearchParameter();
      relatedToKeywordSearchParameter.setKeywords(new Keyword[] {keyword});

      // Create keyword match type search parameter to ensure unique results.
      KeywordMatchTypeSearchParameter keywordMatchTypeSearchParameter =
          new KeywordMatchTypeSearchParameter();
      keywordMatchTypeSearchParameter.setKeywordMatchTypes(
          new KeywordMatchType[] {KeywordMatchType.BROAD});

      selector.setSearchParameters(
          new SearchParameter[] {relatedToKeywordSearchParameter, keywordMatchTypeSearchParameter});

      // Get related keywords.
      TargetingIdeaPage page = targetingIdeaService.get(selector);

      // Display related keywords.
      if (page.getEntries() != null && page.getEntries().length > 0) {
        for (TargetingIdea targetingIdea : page.getEntries()) {
          Map<AttributeType, Attribute> data = MapUtils.toMap(targetingIdea.getData());
          keyword = (Keyword) ((CriterionAttribute) data.get(AttributeType.CRITERION)).getValue();
          Long averageMonthlySearches =
              ((LongAttribute) data.get(AttributeType.AVERAGE_TARGETED_MONTHLY_SEARCHES))
                  .getValue();
          System.out.println(
              "Keyword with text '"
                  + keyword.getText()
                  + "', match type '"
                  + keyword.getMatchType()
                  + "', and average monthly search volume '"
                  + averageMonthlySearches
                  + "' was found.");
        }
      } else {
        System.out.println("No related keywords were found.");
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }