Blame | Last modification | View Log | RSS feed
// 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 adwords.axis.v201302.adwordsforvideo;import com.google.api.ads.adwords.axis.factory.AdWordsServices;import com.google.api.ads.adwords.axis.v201302.cm.Budget;import com.google.api.ads.adwords.axis.v201302.cm.BudgetBudgetDeliveryMethod;import com.google.api.ads.adwords.axis.v201302.cm.BudgetBudgetPeriod;import com.google.api.ads.adwords.axis.v201302.cm.BudgetOperation;import com.google.api.ads.adwords.axis.v201302.cm.BudgetServiceInterface;import com.google.api.ads.adwords.axis.v201302.cm.Money;import com.google.api.ads.adwords.axis.v201302.cm.Operator;import com.google.api.ads.adwords.axis.v201302.video.VideoCampaign;import com.google.api.ads.adwords.axis.v201302.video.VideoCampaignOperation;import com.google.api.ads.adwords.axis.v201302.video.VideoCampaignReturnValue;import com.google.api.ads.adwords.axis.v201302.video.VideoCampaignServiceInterface;import com.google.api.ads.adwords.axis.v201302.video.VideoCampaignStatus;import com.google.api.ads.adwords.lib.client.AdWordsSession;import com.google.api.ads.common.lib.auth.OfflineCredentials;import com.google.api.ads.common.lib.auth.OfflineCredentials.Api;import com.google.api.client.auth.oauth2.Credential;import org.joda.time.DateTime;/*** This example illustrates how to create a video campaign.** Credentials and properties in {@code fromFile()} are pulled from the* "ads.properties" file. See README for more info.** Tags: VideoCampaignService.mutate, BudgetService.mutate** Category: adx-exclude** @author Kevin Winter*/public class AddVideoCampaign {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(Api.ADWORDS).fromFile().build().generateCredential();// Construct an AdWordsSession.AdWordsSession session = new AdWordsSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();AdWordsServices adWordsServices = new AdWordsServices();runExample(adWordsServices, session);}public static void runExample(AdWordsServices adWordsServices, AdWordsSession session) throws Exception {// Get the BudgetService.BudgetServiceInterface budgetService =adWordsServices.get(session, BudgetServiceInterface.class);// Create a budget, which can be shared by multiple video campaigns.Budget sharedBudget = new Budget();sharedBudget.setName("Interplanetary Cruise #" + System.currentTimeMillis());Money budgetAmount = new Money();budgetAmount.setMicroAmount(50000000L);sharedBudget.setAmount(budgetAmount);sharedBudget.setDeliveryMethod(BudgetBudgetDeliveryMethod.STANDARD);sharedBudget.setPeriod(BudgetBudgetPeriod.DAILY);BudgetOperation budgetOperation = new BudgetOperation();budgetOperation.setOperand(sharedBudget);budgetOperation.setOperator(Operator.ADD);// Add the budgetLong budgetId =budgetService.mutate(new BudgetOperation[] {budgetOperation}).getValue(0).getBudgetId();// Get the VideoCampaignService.VideoCampaignServiceInterface videoCampaignService =adWordsServices.get(session, VideoCampaignServiceInterface.class);// Create video campaign.VideoCampaign videoCampaign = new VideoCampaign();videoCampaign.setName("Interplanetary Cruise #" + System.currentTimeMillis());videoCampaign.setStatus(VideoCampaignStatus.PAUSED);// You can optionally provide these field(s).videoCampaign.setStartDate(new DateTime().plusDays(1).toString("yyyyMMdd"));videoCampaign.setBudgetId(budgetId);// Create operations.VideoCampaignOperation operation = new VideoCampaignOperation();operation.setOperand(videoCampaign);operation.setOperator(Operator.ADD);VideoCampaignOperation[] operations = new VideoCampaignOperation[] {operation};// Add video campaigns.VideoCampaignReturnValue result = videoCampaignService.mutate(operations);// Display video campaigns.for (VideoCampaign videoCampaignResult : result.getValue()) {System.out.println("Campaign with name \"" + videoCampaignResult.getName()+ "\" and id \"" + videoCampaignResult.getId() + "\" was added.");}}}