| 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.v201302.basicoperations;
|
|
|
16 |
|
|
|
17 |
import com.google.api.ads.adwords.axis.factory.AdWordsServices;
|
|
|
18 |
import com.google.api.ads.adwords.axis.v201302.cm.AdGroupCriterion;
|
|
|
19 |
import com.google.api.ads.adwords.axis.v201302.cm.AdGroupCriterionOperation;
|
|
|
20 |
import com.google.api.ads.adwords.axis.v201302.cm.AdGroupCriterionReturnValue;
|
|
|
21 |
import com.google.api.ads.adwords.axis.v201302.cm.AdGroupCriterionServiceInterface;
|
|
|
22 |
import com.google.api.ads.adwords.axis.v201302.cm.Criterion;
|
|
|
23 |
import com.google.api.ads.adwords.axis.v201302.cm.Operator;
|
|
|
24 |
import com.google.api.ads.adwords.lib.client.AdWordsSession;
|
|
|
25 |
import com.google.api.ads.common.lib.auth.OfflineCredentials;
|
|
|
26 |
import com.google.api.ads.common.lib.auth.OfflineCredentials.Api;
|
|
|
27 |
import com.google.api.client.auth.oauth2.Credential;
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* This example deletes an ad group criterion using the 'REMOVE' operator. To
|
|
|
31 |
* get ad group criteria, run GetKeywords.java.
|
|
|
32 |
*
|
|
|
33 |
* Credentials and properties in {@code fromFile()} are pulled from the
|
|
|
34 |
* "ads.properties" file. See README for more info.
|
|
|
35 |
*
|
|
|
36 |
* Tags: AdGroupCriterionService.mutate
|
|
|
37 |
*
|
|
|
38 |
* Category: adx-exclude
|
|
|
39 |
*
|
|
|
40 |
* @author Kevin Winter
|
|
|
41 |
*/
|
|
|
42 |
public class DeleteKeyword {
|
|
|
43 |
|
|
|
44 |
public static void main(String[] args) throws Exception {
|
|
|
45 |
// Generate a refreshable OAuth2 credential similar to a ClientLogin token
|
|
|
46 |
// and can be used in place of a service account.
|
|
|
47 |
Credential oAuth2Credential = new OfflineCredentials.Builder()
|
|
|
48 |
.forApi(Api.ADWORDS)
|
|
|
49 |
.fromFile()
|
|
|
50 |
.build()
|
|
|
51 |
.generateCredential();
|
|
|
52 |
|
|
|
53 |
// Construct an AdWordsSession.
|
|
|
54 |
AdWordsSession session = new AdWordsSession.Builder()
|
|
|
55 |
.fromFile()
|
|
|
56 |
.withOAuth2Credential(oAuth2Credential)
|
|
|
57 |
.build();
|
|
|
58 |
|
|
|
59 |
long adGroupId = Long.parseLong("INSERT_AD_GROUP_ID_HERE");
|
|
|
60 |
long criterionId = Long.parseLong("INSERT_CRITERION_ID_HERE");
|
|
|
61 |
|
|
|
62 |
AdWordsServices adWordsServices = new AdWordsServices();
|
|
|
63 |
|
|
|
64 |
runExample(adWordsServices, session, adGroupId, criterionId);
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
public static void runExample(
|
|
|
68 |
AdWordsServices adWordsServices, AdWordsSession session, long adGroupId,
|
|
|
69 |
long criterionId) throws Exception {
|
|
|
70 |
// Get the AdGroupCriterionService.
|
|
|
71 |
AdGroupCriterionServiceInterface adGroupCriterionService =
|
|
|
72 |
adWordsServices.get(session, AdGroupCriterionServiceInterface.class);
|
|
|
73 |
|
|
|
74 |
// Create base class criterion to avoid setting keyword specific fields.
|
|
|
75 |
Criterion criterion = new Criterion();
|
|
|
76 |
criterion.setId(criterionId);
|
|
|
77 |
|
|
|
78 |
// Create ad group criterion.
|
|
|
79 |
AdGroupCriterion adGroupCriterion = new AdGroupCriterion();
|
|
|
80 |
adGroupCriterion.setAdGroupId(adGroupId);
|
|
|
81 |
adGroupCriterion.setCriterion(criterion);
|
|
|
82 |
|
|
|
83 |
// Create operations.
|
|
|
84 |
AdGroupCriterionOperation operation = new AdGroupCriterionOperation();
|
|
|
85 |
operation.setOperand(adGroupCriterion);
|
|
|
86 |
operation.setOperator(Operator.REMOVE);
|
|
|
87 |
|
|
|
88 |
AdGroupCriterionOperation[] operations = new AdGroupCriterionOperation[] {operation};
|
|
|
89 |
|
|
|
90 |
// Delete ad group criteria.
|
|
|
91 |
AdGroupCriterionReturnValue result = adGroupCriterionService.mutate(operations);
|
|
|
92 |
|
|
|
93 |
// Display ad group criteria.
|
|
|
94 |
for (AdGroupCriterion adGroupCriterionResult : result.getValue()) {
|
|
|
95 |
System.out.println("Ad group criterion with ad group id \""
|
|
|
96 |
+ adGroupCriterionResult.getAdGroupId() + "\", criterion id \""
|
|
|
97 |
+ adGroupCriterionResult.getCriterion().getId() + "\", and type \""
|
|
|
98 |
+ adGroupCriterionResult.getCriterion().getCriterionType() + "\" was deleted.");
|
|
|
99 |
}
|
|
|
100 |
}
|
|
|
101 |
}
|