| 9005 |
manish.sha |
1 |
// Copyright 2013 Google Inc. All Rights Reserved.
|
|
|
2 |
//
|
|
|
3 |
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
4 |
// you may not use this file except in compliance with the License.
|
|
|
5 |
// You may obtain a copy of the License at
|
|
|
6 |
//
|
|
|
7 |
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
8 |
//
|
|
|
9 |
// Unless required by applicable law or agreed to in writing, software
|
|
|
10 |
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
12 |
// See the License for the specific language governing permissions and
|
|
|
13 |
// limitations under the License.
|
|
|
14 |
|
|
|
15 |
package adwords.axis.v201302.adwordsforvideo;
|
|
|
16 |
|
|
|
17 |
import com.google.api.ads.adwords.axis.factory.AdWordsServices;
|
|
|
18 |
import com.google.api.ads.adwords.axis.v201302.cm.Budget;
|
|
|
19 |
import com.google.api.ads.adwords.axis.v201302.cm.BudgetBudgetDeliveryMethod;
|
|
|
20 |
import com.google.api.ads.adwords.axis.v201302.cm.BudgetBudgetPeriod;
|
|
|
21 |
import com.google.api.ads.adwords.axis.v201302.cm.BudgetOperation;
|
|
|
22 |
import com.google.api.ads.adwords.axis.v201302.cm.BudgetServiceInterface;
|
|
|
23 |
import com.google.api.ads.adwords.axis.v201302.cm.Money;
|
|
|
24 |
import com.google.api.ads.adwords.axis.v201302.cm.Operator;
|
|
|
25 |
import com.google.api.ads.adwords.axis.v201302.video.VideoCampaign;
|
|
|
26 |
import com.google.api.ads.adwords.axis.v201302.video.VideoCampaignOperation;
|
|
|
27 |
import com.google.api.ads.adwords.axis.v201302.video.VideoCampaignReturnValue;
|
|
|
28 |
import com.google.api.ads.adwords.axis.v201302.video.VideoCampaignServiceInterface;
|
|
|
29 |
import com.google.api.ads.adwords.axis.v201302.video.VideoCampaignStatus;
|
|
|
30 |
import com.google.api.ads.adwords.lib.client.AdWordsSession;
|
|
|
31 |
import com.google.api.ads.common.lib.auth.OfflineCredentials;
|
|
|
32 |
import com.google.api.ads.common.lib.auth.OfflineCredentials.Api;
|
|
|
33 |
import com.google.api.client.auth.oauth2.Credential;
|
|
|
34 |
|
|
|
35 |
import org.joda.time.DateTime;
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
* This example illustrates how to create a video campaign.
|
|
|
39 |
*
|
|
|
40 |
* Credentials and properties in {@code fromFile()} are pulled from the
|
|
|
41 |
* "ads.properties" file. See README for more info.
|
|
|
42 |
*
|
|
|
43 |
* Tags: VideoCampaignService.mutate, BudgetService.mutate
|
|
|
44 |
*
|
|
|
45 |
* Category: adx-exclude
|
|
|
46 |
*
|
|
|
47 |
* @author Kevin Winter
|
|
|
48 |
*/
|
|
|
49 |
public class AddVideoCampaign {
|
|
|
50 |
|
|
|
51 |
public static void main(String[] args) throws Exception {
|
|
|
52 |
// Generate a refreshable OAuth2 credential similar to a ClientLogin token
|
|
|
53 |
// and can be used in place of a service account.
|
|
|
54 |
Credential oAuth2Credential = new OfflineCredentials.Builder()
|
|
|
55 |
.forApi(Api.ADWORDS)
|
|
|
56 |
.fromFile()
|
|
|
57 |
.build()
|
|
|
58 |
.generateCredential();
|
|
|
59 |
|
|
|
60 |
// Construct an AdWordsSession.
|
|
|
61 |
AdWordsSession session = new AdWordsSession.Builder()
|
|
|
62 |
.fromFile()
|
|
|
63 |
.withOAuth2Credential(oAuth2Credential)
|
|
|
64 |
.build();
|
|
|
65 |
|
|
|
66 |
AdWordsServices adWordsServices = new AdWordsServices();
|
|
|
67 |
|
|
|
68 |
runExample(adWordsServices, session);
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
public static void runExample(
|
|
|
72 |
AdWordsServices adWordsServices, AdWordsSession session) throws Exception {
|
|
|
73 |
// Get the BudgetService.
|
|
|
74 |
BudgetServiceInterface budgetService =
|
|
|
75 |
adWordsServices.get(session, BudgetServiceInterface.class);
|
|
|
76 |
|
|
|
77 |
// Create a budget, which can be shared by multiple video campaigns.
|
|
|
78 |
Budget sharedBudget = new Budget();
|
|
|
79 |
sharedBudget.setName("Interplanetary Cruise #" + System.currentTimeMillis());
|
|
|
80 |
Money budgetAmount = new Money();
|
|
|
81 |
budgetAmount.setMicroAmount(50000000L);
|
|
|
82 |
sharedBudget.setAmount(budgetAmount);
|
|
|
83 |
sharedBudget.setDeliveryMethod(BudgetBudgetDeliveryMethod.STANDARD);
|
|
|
84 |
sharedBudget.setPeriod(BudgetBudgetPeriod.DAILY);
|
|
|
85 |
|
|
|
86 |
BudgetOperation budgetOperation = new BudgetOperation();
|
|
|
87 |
budgetOperation.setOperand(sharedBudget);
|
|
|
88 |
budgetOperation.setOperator(Operator.ADD);
|
|
|
89 |
|
|
|
90 |
// Add the budget
|
|
|
91 |
Long budgetId =
|
|
|
92 |
budgetService.mutate(new BudgetOperation[] {budgetOperation}).getValue(0).getBudgetId();
|
|
|
93 |
|
|
|
94 |
// Get the VideoCampaignService.
|
|
|
95 |
VideoCampaignServiceInterface videoCampaignService =
|
|
|
96 |
adWordsServices.get(session, VideoCampaignServiceInterface.class);
|
|
|
97 |
|
|
|
98 |
// Create video campaign.
|
|
|
99 |
VideoCampaign videoCampaign = new VideoCampaign();
|
|
|
100 |
videoCampaign.setName("Interplanetary Cruise #" + System.currentTimeMillis());
|
|
|
101 |
videoCampaign.setStatus(VideoCampaignStatus.PAUSED);
|
|
|
102 |
|
|
|
103 |
// You can optionally provide these field(s).
|
|
|
104 |
videoCampaign.setStartDate(new DateTime().plusDays(1).toString("yyyyMMdd"));
|
|
|
105 |
videoCampaign.setBudgetId(budgetId);
|
|
|
106 |
|
|
|
107 |
// Create operations.
|
|
|
108 |
VideoCampaignOperation operation = new VideoCampaignOperation();
|
|
|
109 |
operation.setOperand(videoCampaign);
|
|
|
110 |
operation.setOperator(Operator.ADD);
|
|
|
111 |
|
|
|
112 |
VideoCampaignOperation[] operations = new VideoCampaignOperation[] {operation};
|
|
|
113 |
|
|
|
114 |
// Add video campaigns.
|
|
|
115 |
VideoCampaignReturnValue result = videoCampaignService.mutate(operations);
|
|
|
116 |
|
|
|
117 |
// Display video campaigns.
|
|
|
118 |
for (VideoCampaign videoCampaignResult : result.getValue()) {
|
|
|
119 |
System.out.println("Campaign with name \"" + videoCampaignResult.getName()
|
|
|
120 |
+ "\" and id \"" + videoCampaignResult.getId() + "\" was added.");
|
|
|
121 |
}
|
|
|
122 |
}
|
|
|
123 |
}
|