| 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.Ad;
|
|
|
19 |
import com.google.api.ads.adwords.axis.v201302.cm.AdGroupAd;
|
|
|
20 |
import com.google.api.ads.adwords.axis.v201302.cm.AdGroupAdOperation;
|
|
|
21 |
import com.google.api.ads.adwords.axis.v201302.cm.AdGroupAdReturnValue;
|
|
|
22 |
import com.google.api.ads.adwords.axis.v201302.cm.AdGroupAdServiceInterface;
|
|
|
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 using the 'REMOVE' operator. To get ads, run
|
|
|
31 |
* GetTextAds.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: AdGroupAdService.mutate
|
|
|
37 |
*
|
|
|
38 |
* @author Kevin Winter
|
|
|
39 |
*/
|
|
|
40 |
public class DeleteAd {
|
|
|
41 |
|
|
|
42 |
public static void main(String[] args) throws Exception {
|
|
|
43 |
// Generate a refreshable OAuth2 credential similar to a ClientLogin token
|
|
|
44 |
// and can be used in place of a service account.
|
|
|
45 |
Credential oAuth2Credential = new OfflineCredentials.Builder()
|
|
|
46 |
.forApi(Api.ADWORDS)
|
|
|
47 |
.fromFile()
|
|
|
48 |
.build()
|
|
|
49 |
.generateCredential();
|
|
|
50 |
|
|
|
51 |
// Construct an AdWordsSession.
|
|
|
52 |
AdWordsSession session = new AdWordsSession.Builder()
|
|
|
53 |
.fromFile()
|
|
|
54 |
.withOAuth2Credential(oAuth2Credential)
|
|
|
55 |
.build();
|
|
|
56 |
|
|
|
57 |
long adGroupId = Long.parseLong("INSERT_AD_GROUP_ID_HERE");
|
|
|
58 |
long adId = Long.parseLong("INSERT_AD_ID_HERE");
|
|
|
59 |
|
|
|
60 |
AdWordsServices adWordsServices = new AdWordsServices();
|
|
|
61 |
|
|
|
62 |
runExample(adWordsServices, session, adGroupId, adId);
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
public static void runExample(
|
|
|
66 |
AdWordsServices adWordsServices, AdWordsSession session, long adGroupId, long adId)
|
|
|
67 |
throws Exception {
|
|
|
68 |
// Get the AdGroupAdService.
|
|
|
69 |
AdGroupAdServiceInterface adGroupAdService =
|
|
|
70 |
adWordsServices.get(session, AdGroupAdServiceInterface.class);
|
|
|
71 |
|
|
|
72 |
// Create base class ad to avoid setting type specific fields.
|
|
|
73 |
Ad ad = new Ad();
|
|
|
74 |
ad.setId(adId);
|
|
|
75 |
|
|
|
76 |
// Create ad group ad.
|
|
|
77 |
AdGroupAd adGroupAd = new AdGroupAd();
|
|
|
78 |
adGroupAd.setAdGroupId(adGroupId);
|
|
|
79 |
adGroupAd.setAd(ad);
|
|
|
80 |
|
|
|
81 |
// Create operations.
|
|
|
82 |
AdGroupAdOperation operation = new AdGroupAdOperation();
|
|
|
83 |
operation.setOperand(adGroupAd);
|
|
|
84 |
operation.setOperator(Operator.REMOVE);
|
|
|
85 |
|
|
|
86 |
AdGroupAdOperation[] operations = new AdGroupAdOperation[] {operation};
|
|
|
87 |
|
|
|
88 |
// Delete ad.
|
|
|
89 |
AdGroupAdReturnValue result = adGroupAdService.mutate(operations);
|
|
|
90 |
|
|
|
91 |
// Display ads.
|
|
|
92 |
for (AdGroupAd adGroupAdResult : result.getValue()) {
|
|
|
93 |
System.out.println("Ad with id \"" + adGroupAdResult.getAd().getId() + "\" and type \""
|
|
|
94 |
+ adGroupAdResult.getAd().getAdType() + "\" was deleted.");
|
|
|
95 |
}
|
|
|
96 |
}
|
|
|
97 |
}
|