Package com.google.api.ads.dfp.v201302

Examples of com.google.api.ads.dfp.v201302.Activity


      // Set the ID of the advertiser (company) that all creatives will be
      // assigned to.
      Long advertiserId = Long.parseLong("INSERT_ADVERTISER_COMPANY_ID_HERE");

      // Create the local custom creative object.
      CustomCreative customCreative = new CustomCreative();
      customCreative.setName("Custom creative");
      customCreative.setAdvertiserId(advertiserId);
      customCreative.setDestinationUrl("http://google.com");

      // Set the custom creative image asset.
      CustomCreativeAsset customCreativeAsset = new CustomCreativeAsset();
      customCreativeAsset.setMacroName("IMAGE_ASSET");
      customCreativeAsset.setAssetByteArray(MediaUtils.getAssetDataFromUrl(
          "http://www.google.com/intl/en/adwords/select/images/samples/inline.jpg"));
      // Filenames must be unique.
      customCreativeAsset.setFileName(String.format("image%s.jpg", System.currentTimeMillis()));
      customCreative.setCustomCreativeAssets(new CustomCreativeAsset[] {customCreativeAsset});

      // Set the HTML snippet using the custom creative asset macro.
      customCreative.setHtmlSnippet("<a href='%%CLICK_URL_UNESC%%%%DEST_URL%%'>" +
          "<img src='%%FILE:" + customCreativeAsset.getMacroName() + "%%'/>" +
          "</a><br>Click above for great deals!");

      // Set the creative size.
      customCreative.setSize(new Size(300, 250, false));

      // Create the custom creative on the server.
      customCreative = (CustomCreative) creativeService.createCreative(customCreative);

      if (customCreative != null) {
        System.out.println("A custom creative with ID \"" + customCreative.getId()
            + "\", name \"" + customCreative.getName()
            + "\", and size {" + customCreative.getSize().getWidth()
            + ", " + customCreative.getSize().getHeight() + "} was created and\n"
            + " can be previewed at: " + customCreative.getPreviewUrl());
      } else {
        System.out.println("No creative created.");
      }
    } catch (Exception e) {
      e.printStackTrace();
View Full Code Here


      customCreative.setName("Custom creative");
      customCreative.setAdvertiserId(advertiserId);
      customCreative.setDestinationUrl("http://google.com");

      // Set the custom creative image asset.
      CustomCreativeAsset customCreativeAsset = new CustomCreativeAsset();
      customCreativeAsset.setMacroName("IMAGE_ASSET");
      customCreativeAsset.setAssetByteArray(MediaUtils.getAssetDataFromUrl(
          "http://www.google.com/intl/en/adwords/select/images/samples/inline.jpg"));
      // Filenames must be unique.
      customCreativeAsset.setFileName(String.format("image%s.jpg", System.currentTimeMillis()));
      customCreative.setCustomCreativeAssets(new CustomCreativeAsset[] {customCreativeAsset});

      // Set the HTML snippet using the custom creative asset macro.
      customCreative.setHtmlSnippet("<a href='%%CLICK_URL_UNESC%%%%DEST_URL%%'>" +
          "<img src='%%FILE:" + customCreativeAsset.getMacroName() + "%%'/>" +
          "</a><br>Click above for great deals!");

      // Set the creative size.
      customCreative.setSize(new Size(300, 250, false));
View Full Code Here

   */
  public static Date fromDate(java.util.Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);

    Date dfpDate = new Date();
    dfpDate.setYear(calendar.get(Calendar.YEAR));
    dfpDate.setMonth(calendar.get(Calendar.MONTH) + 1);
    dfpDate.setDay(calendar.get(Calendar.DAY_OF_MONTH));

    return dfpDate;
  }
View Full Code Here

   * @param date the DFP {@code Date} object to convert to a Java {@code Date}
   * @param timeZoneId the timezone of the date
   * @return the DFP {@code Date} object as a Java {@code Date} in the timezone
   */
  public static java.util.Date toDate(Date date, String timeZoneId) {
    return DateTimeUtils.toDate(new DateTime(date, 0, 0, 0, timeZoneId));
  }
View Full Code Here

   */
  public static DateTime fromDate(java.util.Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);

    DateTime dfpDateTime = new DateTime();
    dfpDateTime.setDate(DateUtils.fromDate(date));
    dfpDateTime.setHour(calendar.get(Calendar.HOUR_OF_DAY));
    dfpDateTime.setMinute(calendar.get(Calendar.MINUTE));
    dfpDateTime.setSecond(calendar.get(Calendar.SECOND));

    return dfpDateTime;
  }
View Full Code Here

   * @param timeZoneId the timezone of the publisher
   * @return a {@code DateTime} object representing the present date in the
   *     publisher's timezone
   */
  public static DateTime today(String timeZoneId) {
    DateTime dateTime =
        fromDate(Calendar.getInstance(TimeZone.getTimeZone(timeZoneId)).getTime());
    dateTime.setHour(0);
    dateTime.setMinute(0);
    dateTime.setSecond(0);
    return dateTime;
  }
View Full Code Here

      } else if (value instanceof String) {
        return new TextValue(null, (String) value);
      } else if (value instanceof Long) {
        return new NumberValue(null, value.toString());
      } else if (value instanceof DateTime) {
        return new DateTimeValue(null, (DateTime) value);
      } else {
        throw new IllegalArgumentException("Unexpected Value type ["
            + value.getClass() + "]");
      }
    }
View Full Code Here

      if (page.getResults() != null) {
        Creative[] creatives = page.getResults();
        long[] oldIds = new long[creatives.length];
        for (int i = 0; i < creatives.length; i++) {
          ImageCreative imageCreative = (ImageCreative) creatives[i];
          oldIds[i] = imageCreative.getId();
          imageCreative.setId(null);
          imageCreative.setAdvertiserId(imageCreative.getAdvertiserId());
          imageCreative.setName(
              imageCreative.getName() + " (Copy #" + System.currentTimeMillis() + ")");

          // Create image asset.
          CreativeAsset creativeAsset = new CreativeAsset();
          creativeAsset.setFileName("image.jpg");
          creativeAsset.setAssetByteArray(
              MediaUtils.getAssetDataFromUrl(imageCreative.getPrimaryImageAsset().getAssetUrl()));
          creativeAsset.setSize(imageCreative.getPrimaryImageAsset().getSize());
          imageCreative.setPrimaryImageAsset(creativeAsset);

          creatives[i] = imageCreative;
        }

        // Create the copied creative.
View Full Code Here

        Creative[] creatives = page.getResults();

        // Update each local creative object by changing its destination URL.
        for (Creative creative : creatives) {
          if (creative instanceof ImageCreative) {
            ImageCreative imageCreative = (ImageCreative) creative;
            imageCreative.setDestinationUrl("http://news.google.com");
          }
        }

        // Update the creatives on the server.
        creatives = creativeService.updateCreatives(creatives);

        if (creatives != null) {
          for (Creative creative : creatives) {
            if (creative instanceof ImageCreative) {
              ImageCreative imageCreative = (ImageCreative) creative;
              System.out.println("An image creative with ID \"" + imageCreative.getId()
                  + "\" and destination URL \"" + imageCreative.getDestinationUrl()
                  + "\" was updated.");
            }
          }
        } else {
          System.out.println("No creatives updated.");
View Full Code Here

        size.setWidth(300);
        size.setHeight(250);
        size.setIsAspectRatio(false);

        // Create an image creative.
        ImageCreative imageCreative = new ImageCreative();
        imageCreative.setName("Image creative #" + i);
        imageCreative.setAdvertiserId(advertiserId);
        imageCreative.setDestinationUrl("http://google.com");
        imageCreative.setSize(size);

        // Create image asset.
        CreativeAsset creativeAsset = new CreativeAsset();
        creativeAsset.setFileName("image.jpg");
        creativeAsset.setAssetByteArray(MediaUtils.getAssetDataFromUrl(
            "http://www.google.com/intl/en/adwords/select/images/samples/inline.jpg"));
        creativeAsset.setSize(size);
        imageCreative.setPrimaryImageAsset(creativeAsset);

        imageCreatives[i] = imageCreative;
      }

      // Create the image creatives on the server.
      imageCreatives = creativeService.createCreatives(imageCreatives);

      if (imageCreatives != null) {
        for (Creative creative : imageCreatives) {
          // Use instanceof to determine what type of creative was returned.
          if (creative instanceof ImageCreative) {
            ImageCreative imageCreative = (ImageCreative) creative;
            System.out.println("An image creative with ID \"" + imageCreative.getId()
                + "\", name \"" + imageCreative.getName()
                + "\", and size {" + imageCreative.getSize().getWidth()
                + ", " + imageCreative.getSize().getHeight() + "} was created and\n"
                + " can be previewed at: " + imageCreative.getPreviewUrl());
          } else {
            System.out.println("A creative with ID \"" + creative.getId()
                + "\", name \"" + creative.getName()
                + "\", and type \"" + creative.getCreativeType() + "\" was created.");
          }
View Full Code Here

TOP

Related Classes of com.google.api.ads.dfp.v201302.Activity

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.