Package v201309

Source Code of v201309.AddClickToDownloadAd

// Copyright 2013 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package v201309;

import com.google.api.adwords.lib.AdWordsService;
import com.google.api.adwords.lib.AdWordsServiceLogger;
import com.google.api.adwords.lib.AdWordsUser;
import com.google.api.adwords.v201309.cm.AdGroupAd;
import com.google.api.adwords.v201309.cm.AdGroupAdOperation;
import com.google.api.adwords.v201309.cm.AdGroupAdReturnValue;
import com.google.api.adwords.v201309.cm.AdGroupAdServiceInterface;
import com.google.api.adwords.v201309.cm.AdGroupAdStatus;
import com.google.api.adwords.v201309.cm.Operator;
import com.google.api.adwords.v201309.cm.TemplateAd;
import com.google.api.adwords.v201309.cm.TemplateElement;
import com.google.api.adwords.v201309.cm.TemplateElementField;
import com.google.api.adwords.v201309.cm.TemplateElementFieldType;

/**
* This example adds a click-to-download templateAd to given ad group. To get adGroupId, run
* AddAdGroup.java.
*
* Tags: AdGroupAdService.mutate
*
* @category adx-exclude
* @author thagikura@google.com (Takeshi Hagikura)
*/
public class AddClickToDownloadAd {

  public static void main(String[] args) throws Exception {
    AdWordsServiceLogger.log();

    // Get AdWordsUser from "~/adwords.properties".
    AdWordsUser user = new AdWordsUser();
    long adGroupId = Long.parseLong("INSERT_AD_GROUP_ID_HERE");
   
    // Get the AdGroupAdService.
    AdGroupAdServiceInterface adGroupAdService =
        user.getService(AdWordsService.V201309.ADGROUP_AD_SERVICE);

    // Create the template elements for the ad. You can refer to
    //   https://developers.google.com/adwords/api/docs/appendix/templateads
    // for the list of available template fields.
    TemplateAd clickToDownloadAppAd = new TemplateAd();
    clickToDownloadAppAd.setName("Ad for jupiter adventure game");
    clickToDownloadAppAd.setTemplateId(353L);

    clickToDownloadAppAd.setUrl(
        "http://play.google.com/store/apps/details?id=com.example.jupiteradventure");
    clickToDownloadAppAd.setDisplayUrl("play.google.com");

    TemplateElementField headline = new TemplateElementField();
    headline.setName("headline");
    headline.setFieldText("Enjoy a jupiter Adventure");
    headline.setType(TemplateElementFieldType.TEXT);

    TemplateElementField description1 = new TemplateElementField();
    description1.setName("description1");
    description1.setFieldText("Realistic physics simulation");
    description1.setType(TemplateElementFieldType.TEXT);

    TemplateElementField description2 = new TemplateElementField();
    description2.setName("description2");
    description2.setFieldText("Race against players online");
    description2.setType(TemplateElementFieldType.TEXT);

    TemplateElementField appId = new TemplateElementField();
    appId.setName("appId");
    appId.setFieldText("com.example.jupiteradventure");
    appId.setType(TemplateElementFieldType.TEXT);

    TemplateElementField appStore = new TemplateElementField();
    appStore.setName("appStore");
    appStore.setFieldText("2");
    appStore.setType(TemplateElementFieldType.ENUM);

    TemplateElement adData = new TemplateElement();
    adData.setUniqueName("adData");
    adData.setFields(
        new TemplateElementField[] {headline, description1, description2, appId, appStore});

    clickToDownloadAppAd.setTemplateElements(new TemplateElement[] {adData});

    // Create the AdGroupAd.
    AdGroupAd clickToDownloadAppAdGroupAd = new AdGroupAd();
    clickToDownloadAppAdGroupAd.setAdGroupId(adGroupId);
    clickToDownloadAppAdGroupAd.setAd(clickToDownloadAppAd);

    // Optional: Set the status.
    clickToDownloadAppAdGroupAd.setStatus(AdGroupAdStatus.PAUSED);

    // Create the operation.
    AdGroupAdOperation operation = new AdGroupAdOperation();
    operation.setOperator(Operator.ADD);
    operation.setOperand(clickToDownloadAppAdGroupAd);

    // Create the ads.
    AdGroupAdReturnValue result = adGroupAdService.mutate(new AdGroupAdOperation[] {operation});

    for (AdGroupAd adGroupAd : result.getValue()) {
      System.out.printf(
          "New click-to-download ad with id = \"%d\" and url = \"%s\" was created.",
          adGroupAd.getAd().getId(), adGroupAd.getAd().getUrl());
    }
  }
}
TOP

Related Classes of v201309.AddClickToDownloadAd

TOP
Copyright © 2018 www.massapi.com. 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.