| 9005 |
manish.sha |
1 |
// Copyright 2012 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.v201306.accountmanagement;
|
|
|
16 |
|
|
|
17 |
import com.google.api.ads.adwords.axis.factory.AdWordsServices;
|
|
|
18 |
import com.google.api.ads.adwords.axis.v201306.cm.Operator;
|
|
|
19 |
import com.google.api.ads.adwords.axis.v201306.mcm.ManagedCustomer;
|
|
|
20 |
import com.google.api.ads.adwords.axis.v201306.mcm.ManagedCustomerOperation;
|
|
|
21 |
import com.google.api.ads.adwords.axis.v201306.mcm.ManagedCustomerReturnValue;
|
|
|
22 |
import com.google.api.ads.adwords.axis.v201306.mcm.ManagedCustomerServiceInterface;
|
|
|
23 |
import com.google.api.ads.adwords.lib.client.AdWordsSession;
|
|
|
24 |
import com.google.api.ads.common.lib.auth.OfflineCredentials;
|
|
|
25 |
import com.google.api.ads.common.lib.auth.OfflineCredentials.Api;
|
|
|
26 |
import com.google.api.client.auth.oauth2.Credential;
|
|
|
27 |
|
|
|
28 |
import org.joda.time.DateTime;
|
|
|
29 |
|
|
|
30 |
/**
|
|
|
31 |
* This example creates a new account under an MCC account.
|
|
|
32 |
*
|
|
|
33 |
* Note: this example must be run using the credentials of an MCC account, and
|
|
|
34 |
* by default the new account will only be accessible via the parent MCC
|
|
|
35 |
* account.
|
|
|
36 |
*
|
|
|
37 |
* Credentials and properties in {@code fromFile()} are pulled from the
|
|
|
38 |
* "ads.properties" file. See README for more info.
|
|
|
39 |
*
|
|
|
40 |
* Note: this code example won't work with test accounts. See
|
|
|
41 |
* https://developers.google.com/adwords/api/docs/test-accounts
|
|
|
42 |
*
|
|
|
43 |
* Tags: ManagedCustomerService.mutate
|
|
|
44 |
*
|
|
|
45 |
* Category: adx-exclude
|
|
|
46 |
*
|
|
|
47 |
* @author Adam Rogal
|
|
|
48 |
*/
|
|
|
49 |
public class CreateAccount {
|
|
|
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 CampaignService.
|
|
|
74 |
ManagedCustomerServiceInterface managedCustomerService =
|
|
|
75 |
adWordsServices.get(session, ManagedCustomerServiceInterface.class);
|
|
|
76 |
|
|
|
77 |
// Create account.
|
|
|
78 |
ManagedCustomer customer = new ManagedCustomer();
|
|
|
79 |
customer.setName("Customer created with ManagedCustomerService on "
|
|
|
80 |
+ new DateTime().toString());
|
|
|
81 |
customer.setCurrencyCode("EUR");
|
|
|
82 |
customer.setDateTimeZone("Europe/London");
|
|
|
83 |
|
|
|
84 |
// Create operations.
|
|
|
85 |
ManagedCustomerOperation operation = new ManagedCustomerOperation();
|
|
|
86 |
operation.setOperand(customer);
|
|
|
87 |
operation.setOperator(Operator.ADD);
|
|
|
88 |
|
|
|
89 |
ManagedCustomerOperation[] operations = new ManagedCustomerOperation[] {operation};
|
|
|
90 |
|
|
|
91 |
// Add account.
|
|
|
92 |
ManagedCustomerReturnValue result = managedCustomerService.mutate(operations);
|
|
|
93 |
|
|
|
94 |
// Display accounts.
|
|
|
95 |
for (ManagedCustomer customerResult : result.getValue()) {
|
|
|
96 |
System.out.println("Account with customer ID \"" + customerResult.getCustomerId()
|
|
|
97 |
+ "\" was created.");
|
|
|
98 |
}
|
|
|
99 |
}
|
|
|
100 |
}
|