Package com.google.api.ads.dfp.axis.v201306

Examples of com.google.api.ads.dfp.axis.v201306.DateTime


  private static final String CREATIVE_ID = "INSERT_CREATIVE_ID_HERE";

  public static void runExample(DfpServices dfpServices, DfpSession session, long lineItemId,
      long creativeId) throws Exception {
    // Get the LineItemCreativeAssociationService.
    LineItemCreativeAssociationServiceInterface licaService =
        dfpServices.get(session, LineItemCreativeAssociationServiceInterface.class);

    // Create a line item creative association.
    LineItemCreativeAssociation lica = new LineItemCreativeAssociation();
    lica.setLineItemId(lineItemId);
    lica.setCreativeId(creativeId);

    // Create the line item creative association on the server.
    LineItemCreativeAssociation[] licas =
        licaService.createLineItemCreativeAssociations(
            new LineItemCreativeAssociation[] {lica});

    for (LineItemCreativeAssociation createdLica : licas) {
      System.out.printf("A LICA with line item ID \"%d\" and creative ID \"%d\" was created.\n",
          createdLica.getLineItemId(), createdLica.getCreativeId());
View Full Code Here


    // Get the CustomFieldService.
    CustomFieldServiceInterface customFieldService =
        dfpServices.get(session, CustomFieldServiceInterface.class);

    // Get the LineItemService.
    LineItemServiceInterface lineItemService =
        dfpServices.get(session, LineItemServiceInterface.class);

    // Get the drop-down custom field ID.
    long dropDownCustomFieldId =
        customFieldService.getCustomFieldOption(customFieldOptionId).getCustomFieldId();

    // Get the line item.
    LineItem lineItem = lineItemService.getLineItem(lineItemId);

    // Create number custom field value.
    NumberValue numberValue = new NumberValue();
    numberValue.setValue("12345");

    CustomFieldValue numberCustomFieldValue = new CustomFieldValue();
    numberCustomFieldValue.setCustomFieldId(numberCustomFieldId);
    numberCustomFieldValue.setValue(numberValue);

    // Create drop-down custom field value.
    DropDownCustomFieldValue dropDownCustomFieldValue = new DropDownCustomFieldValue();
    dropDownCustomFieldValue.setCustomFieldId(dropDownCustomFieldId);
    dropDownCustomFieldValue.setCustomFieldOptionId(customFieldOptionId);

    // Create a combined custom field value list of existing different custom
    // field values and new ones.
    List<BaseCustomFieldValue> combinedCustomFieldValues = Lists.newArrayList();
    if (lineItem.getCustomFieldValues() != null) {
      for (BaseCustomFieldValue existingCustomFieldValue : lineItem.getCustomFieldValues()) {
        if (!existingCustomFieldValue.getCustomFieldId().equals(numberCustomFieldId)
            && !existingCustomFieldValue.getCustomFieldId().equals(dropDownCustomFieldId)) {
          combinedCustomFieldValues.add(existingCustomFieldValue);
        }
      }
    }
    combinedCustomFieldValues.addAll(
        Arrays.asList(numberCustomFieldValue, dropDownCustomFieldValue));

    // Set the combined custom field values.
    lineItem.setCustomFieldValues(combinedCustomFieldValues.toArray(new BaseCustomFieldValue[]{}));

    // Update the line item on the server.
    LineItem[] lineItems = lineItemService.updateLineItems(new LineItem[] {lineItem});

    for (LineItem updatedLineItem : lineItems) {
      // Get a string representation of the custom field values.
      List<String> customFieldValueStrings = Lists.transform(
          Arrays.asList(updatedLineItem.getCustomFieldValues()),
View Full Code Here

    // Get the CustomTargetingService.
    CustomTargetingServiceInterface customTargetingService =
        dfpServices.get(session, CustomTargetingServiceInterface.class);

    // Get the NetworkService.
    NetworkServiceInterface networkService =
        dfpServices.get(session, NetworkServiceInterface.class);

    // Get content browse custom targeting key ID.
    long contentBrowseCustomTargetingKeyId =
        networkService.getCurrentNetwork().getContentBrowseCustomTargetingKeyId();

    if (contentBrowseCustomTargetingKeyId == 0) {
      throw new RuntimeException("Your network does not have content categories enabled.");     
    }
View Full Code Here

    // Get the line item.
    LineItem lineItem = lineItemService.getLineItem(lineItemId);

    // Create number custom field value.
    NumberValue numberValue = new NumberValue();
    numberValue.setValue("12345");

    CustomFieldValue numberCustomFieldValue = new CustomFieldValue();
    numberCustomFieldValue.setCustomFieldId(numberCustomFieldId);
    numberCustomFieldValue.setValue(numberValue);
View Full Code Here

    // Get the PlacementService.
    PlacementServiceInterface placementService =
        dfpServices.get(session, PlacementServiceInterface.class);

    // Get the placement.
    Placement placement = placementService.getPlacement(placementId);

    // Enable AdSense targeting.
    placement.setTargetingDescription(
        (placement.getDescription() == null || placement.getDescription().isEmpty())
        ? "Insert description here." : placement.getDescription());
    placement.setTargetingAdLocation("All images on sports pages.");
    placement.setTargetingSiteName("https://news.google.com");
    placement.setIsAdSenseTargetingEnabled(true);

    // Update the placement on the server.
    Placement[] placements = placementService.updatePlacements(new Placement[] {placement});

    for (Placement updatedPlacement : placements) {
View Full Code Here

    List<Placement> placementsToCreate = Lists.newArrayList();

    // Only create placements with one or more ad unit.
    if (!mediumSquareAdUnitIds.isEmpty()) {
      // Create medium square placement.
      Placement mediumSquareAdUnitPlacement = new Placement();
      mediumSquareAdUnitPlacement.setName("Medium Square AdUnit Placement #"
          + new Random().nextInt(Integer.MAX_VALUE));
      mediumSquareAdUnitPlacement.setDescription(
          "Contains ad units that can hold creatives of size 300x250");
      mediumSquareAdUnitPlacement.setTargetedAdUnitIds(
          mediumSquareAdUnitIds.toArray(new String[] {}));

      placementsToCreate.add(mediumSquareAdUnitPlacement);
    }

    if (!skyscraperAdUnitIds.isEmpty()) {
      // Create skyscraper placement.
      Placement skyscraperAdUnitPlacement = new Placement();
      skyscraperAdUnitPlacement.setName(
          "Skyscraper AdUnit Placement #" + new Random().nextInt(Integer.MAX_VALUE));
      skyscraperAdUnitPlacement.setDescription(
          "Contains ad units that can hold creatives of size 120x600");
      skyscraperAdUnitPlacement.setTargetedAdUnitIds(skyscraperAdUnitIds.toArray(new String[] {}));
      placementsToCreate.add(skyscraperAdUnitPlacement);
    }

    if (!bannerAdUnitIds.isEmpty()) {
      // Create banner placement.
      Placement bannerAdUnitPlacement = new Placement();
      bannerAdUnitPlacement.setName(
          "Banner AdUnit Placement #" + new Random().nextInt(Integer.MAX_VALUE));
      bannerAdUnitPlacement.setDescription(
          "Contains ad units that can hold creatives of size 468x60");
      bannerAdUnitPlacement.setTargetedAdUnitIds(bannerAdUnitIds.toArray(new String[] {}));
      placementsToCreate.add(bannerAdUnitPlacement);
    }

    if (!placementsToCreate.isEmpty()) {
      // Create the placements on the server.
View Full Code Here

    // Default for total result set size.
    int totalResultSetSize = 0;

    do {
      // Get placements by statement.
      PlacementPage page =
          placementService.getPlacementsByStatement(statementBuilder.toStatement());

      if (page.getResults() != null) {
        totalResultSetSize = page.getTotalResultSetSize();
        int i = page.getStartIndex();
        for (Placement placement : page.getResults()) {
          System.out.printf(
              "%d) Placement with ID \"%d\" and name \"%s\" was found.\n", i++,
              placement.getId(), placement.getName());
        }
      }
View Full Code Here

    // Default for total result set size.
    int totalResultSetSize = 0;

    do {
      // Get placements by statement.
      PlacementPage page =
          placementService.getPlacementsByStatement(statementBuilder.toStatement());

      if (page.getResults() != null) {
        totalResultSetSize = page.getTotalResultSetSize();
        int i = page.getStartIndex();
        for (Placement placement : page.getResults()) {
          System.out.printf(
              "%d) Placement with ID \"%d\" and name \"%s\" was found.\n", i++,
              placement.getId(), placement.getName());
        }
      }
View Full Code Here

  private static final String PLACEMENT_ID = "INSERT_PLACEMENT_ID_HERE";

  public static void runExample(DfpServices dfpServices, DfpSession session, long placementId)
      throws Exception {
    // Get the PlacementService.
    PlacementServiceInterface placementService =
        dfpServices.get(session, PlacementServiceInterface.class);

    // Get the placement.
    Placement placement = placementService.getPlacement(placementId);

    // Enable AdSense targeting.
    placement.setTargetingDescription(
        (placement.getDescription() == null || placement.getDescription().isEmpty())
        ? "Insert description here." : placement.getDescription());
    placement.setTargetingAdLocation("All images on sports pages.");
    placement.setTargetingSiteName("https://news.google.com");
    placement.setIsAdSenseTargetingEnabled(true);

    // Update the placement on the server.
    Placement[] placements = placementService.updatePlacements(new Placement[] {placement});

    for (Placement updatedPlacement : placements) {
      System.out.printf("Placement with ID \"%d\" and name \"%s\" was updated.\n",
          updatedPlacement.getId(), updatedPlacement.getName());
    }
View Full Code Here

*/
public class CreatePlacements {

  public static void runExample(DfpServices dfpServices, DfpSession session) throws Exception {
    // Get the PlacementService.
    PlacementServiceInterface placementService =
        dfpServices.get(session, PlacementServiceInterface.class);

    // Get all ad units.
    List<AdUnit> adUnits = getAllAdUnits(dfpServices, session);

    // Partition ad units by their size.
    Set<String> mediumSquareAdUnitIds = Sets.newHashSet();
    Set<String> skyscraperAdUnitIds = Sets.newHashSet();
    Set<String> bannerAdUnitIds = Sets.newHashSet();

    for (AdUnit adUnit : adUnits) {
      if (adUnit.getParentId() != null && adUnit.getAdUnitSizes() != null) {
        for (AdUnitSize adUnitSize : adUnit.getAdUnitSizes()) {
          Size size = adUnitSize.getSize();
          if (size.getWidth() == 300 && size.getHeight() == 250) {
            mediumSquareAdUnitIds.add(adUnit.getId());
          } else if (size.getWidth() == 120 && size.getHeight() == 600) {
            skyscraperAdUnitIds.add(adUnit.getId());
          } else if (size.getWidth() == 468 && size.getHeight() == 60) {
            bannerAdUnitIds.add(adUnit.getId());
          }
        }
      }
    }

    List<Placement> placementsToCreate = Lists.newArrayList();

    // Only create placements with one or more ad unit.
    if (!mediumSquareAdUnitIds.isEmpty()) {
      // Create medium square placement.
      Placement mediumSquareAdUnitPlacement = new Placement();
      mediumSquareAdUnitPlacement.setName("Medium Square AdUnit Placement #"
          + new Random().nextInt(Integer.MAX_VALUE));
      mediumSquareAdUnitPlacement.setDescription(
          "Contains ad units that can hold creatives of size 300x250");
      mediumSquareAdUnitPlacement.setTargetedAdUnitIds(
          mediumSquareAdUnitIds.toArray(new String[] {}));

      placementsToCreate.add(mediumSquareAdUnitPlacement);
    }

    if (!skyscraperAdUnitIds.isEmpty()) {
      // Create skyscraper placement.
      Placement skyscraperAdUnitPlacement = new Placement();
      skyscraperAdUnitPlacement.setName(
          "Skyscraper AdUnit Placement #" + new Random().nextInt(Integer.MAX_VALUE));
      skyscraperAdUnitPlacement.setDescription(
          "Contains ad units that can hold creatives of size 120x600");
      skyscraperAdUnitPlacement.setTargetedAdUnitIds(skyscraperAdUnitIds.toArray(new String[] {}));
      placementsToCreate.add(skyscraperAdUnitPlacement);
    }

    if (!bannerAdUnitIds.isEmpty()) {
      // Create banner placement.
      Placement bannerAdUnitPlacement = new Placement();
      bannerAdUnitPlacement.setName(
          "Banner AdUnit Placement #" + new Random().nextInt(Integer.MAX_VALUE));
      bannerAdUnitPlacement.setDescription(
          "Contains ad units that can hold creatives of size 468x60");
      bannerAdUnitPlacement.setTargetedAdUnitIds(bannerAdUnitIds.toArray(new String[] {}));
      placementsToCreate.add(bannerAdUnitPlacement);
    }

    if (!placementsToCreate.isEmpty()) {
      // Create the placements on the server.
      Placement[] placements =
          placementService.createPlacements(placementsToCreate.toArray(new Placement[] {}));

      for (Placement createdPlacement : placements) {
        System.out.printf(
            "A placement with ID \"%d\", name \"%s\", and containing ad units [%s] was created.\n",
            createdPlacement.getId(), createdPlacement.getName(),
View Full Code Here

TOP

Related Classes of com.google.api.ads.dfp.axis.v201306.DateTime

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.