| 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.accountmanagement;
|
|
|
16 |
|
|
|
17 |
import com.google.api.ads.adwords.axis.factory.AdWordsServices;
|
|
|
18 |
import com.google.api.ads.adwords.axis.v201302.cm.Paging;
|
|
|
19 |
import com.google.api.ads.adwords.axis.v201302.mcm.Alert;
|
|
|
20 |
import com.google.api.ads.adwords.axis.v201302.mcm.AlertPage;
|
|
|
21 |
import com.google.api.ads.adwords.axis.v201302.mcm.AlertQuery;
|
|
|
22 |
import com.google.api.ads.adwords.axis.v201302.mcm.AlertSelector;
|
|
|
23 |
import com.google.api.ads.adwords.axis.v201302.mcm.AlertServiceInterface;
|
|
|
24 |
import com.google.api.ads.adwords.axis.v201302.mcm.AlertSeverity;
|
|
|
25 |
import com.google.api.ads.adwords.axis.v201302.mcm.AlertType;
|
|
|
26 |
import com.google.api.ads.adwords.axis.v201302.mcm.ClientSpec;
|
|
|
27 |
import com.google.api.ads.adwords.axis.v201302.mcm.FilterSpec;
|
|
|
28 |
import com.google.api.ads.adwords.axis.v201302.mcm.TriggerTimeSpec;
|
|
|
29 |
import com.google.api.ads.adwords.lib.client.AdWordsSession;
|
|
|
30 |
import com.google.api.ads.common.lib.auth.OfflineCredentials;
|
|
|
31 |
import com.google.api.ads.common.lib.auth.OfflineCredentials.Api;
|
|
|
32 |
import com.google.api.client.auth.oauth2.Credential;
|
|
|
33 |
|
|
|
34 |
/**
|
|
|
35 |
* This example gets all alerts for all clients of an MCC account. This example
|
|
|
36 |
* assumes the email and password belong to an MCC.
|
|
|
37 |
*
|
|
|
38 |
* Note: this code example won't work with test accounts. See
|
|
|
39 |
* https://developers.google.com/adwords/api/docs/test-accounts
|
|
|
40 |
*
|
|
|
41 |
* Tags: AlertService.get
|
|
|
42 |
*
|
|
|
43 |
* @author Kevin Winter
|
|
|
44 |
*/
|
|
|
45 |
public class GetAccountAlerts {
|
|
|
46 |
|
|
|
47 |
private static final int PAGE_SIZE = 100;
|
|
|
48 |
|
|
|
49 |
public static void main(String[] args) throws Exception {
|
|
|
50 |
// Generate a refreshable OAuth2 credential similar to a ClientLogin token
|
|
|
51 |
// and can be used in place of a service account.
|
|
|
52 |
Credential oAuth2Credential = new OfflineCredentials.Builder()
|
|
|
53 |
.forApi(Api.ADWORDS)
|
|
|
54 |
.fromFile()
|
|
|
55 |
.build()
|
|
|
56 |
.generateCredential();
|
|
|
57 |
|
|
|
58 |
// Construct an AdWordsSession.
|
|
|
59 |
AdWordsSession session = new AdWordsSession.Builder()
|
|
|
60 |
.fromFile()
|
|
|
61 |
.withOAuth2Credential(oAuth2Credential)
|
|
|
62 |
.build();
|
|
|
63 |
|
|
|
64 |
AdWordsServices adWordsServices = new AdWordsServices();
|
|
|
65 |
|
|
|
66 |
runExample(adWordsServices, session);
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
public static void runExample(AdWordsServices adWordsServices, AdWordsSession session)
|
|
|
70 |
throws Exception {
|
|
|
71 |
// Get the AlertService.
|
|
|
72 |
AlertServiceInterface alertService =
|
|
|
73 |
adWordsServices.get(session, AlertServiceInterface.class);
|
|
|
74 |
|
|
|
75 |
// Create alert query.
|
|
|
76 |
AlertQuery alertQuery = new AlertQuery();
|
|
|
77 |
alertQuery.setClientSpec(ClientSpec.ALL);
|
|
|
78 |
alertQuery.setFilterSpec(FilterSpec.ALL);
|
|
|
79 |
alertQuery.setTypes(new AlertType[] {AlertType.ACCOUNT_BUDGET_BURN_RATE,
|
|
|
80 |
AlertType.ACCOUNT_BUDGET_ENDING, AlertType.ACCOUNT_ON_TARGET, AlertType.CAMPAIGN_ENDED,
|
|
|
81 |
AlertType.CAMPAIGN_ENDING, AlertType.CREDIT_CARD_EXPIRING, AlertType.DECLINED_PAYMENT,
|
|
|
82 |
AlertType.MANAGER_LINK_PENDING, AlertType.MISSING_BANK_REFERENCE_NUMBER,
|
|
|
83 |
AlertType.PAYMENT_NOT_ENTERED, AlertType.TV_ACCOUNT_BUDGET_ENDING,
|
|
|
84 |
AlertType.TV_ACCOUNT_ON_TARGET, AlertType.TV_ZERO_DAILY_SPENDING_LIMIT,
|
|
|
85 |
AlertType.USER_INVITE_ACCEPTED, AlertType.USER_INVITE_PENDING,
|
|
|
86 |
AlertType.ZERO_DAILY_SPENDING_LIMIT});
|
|
|
87 |
alertQuery.setSeverities(new AlertSeverity[] {AlertSeverity.GREEN, AlertSeverity.YELLOW,
|
|
|
88 |
AlertSeverity.RED});
|
|
|
89 |
alertQuery.setTriggerTimeSpec(TriggerTimeSpec.ALL_TIME);
|
|
|
90 |
|
|
|
91 |
int offset = 0;
|
|
|
92 |
|
|
|
93 |
// Create selector.
|
|
|
94 |
AlertSelector selector = new AlertSelector();
|
|
|
95 |
selector.setQuery(alertQuery);
|
|
|
96 |
selector.setPaging(new Paging(offset, PAGE_SIZE));
|
|
|
97 |
|
|
|
98 |
AlertPage page = null;
|
|
|
99 |
do {
|
|
|
100 |
// Get all alerts.
|
|
|
101 |
page = alertService.get(selector);
|
|
|
102 |
|
|
|
103 |
// Display alerts.
|
|
|
104 |
if (page.getEntries() != null && page.getEntries().length > 0) {
|
|
|
105 |
for (Alert alert : page.getEntries()) {
|
|
|
106 |
System.out.printf(
|
|
|
107 |
"Alert of type '%s' and severity '%s' for account '%d' was found.\n",
|
|
|
108 |
alert.getAlertType(), alert.getAlertSeverity(),
|
|
|
109 |
alert.getClientCustomerId());
|
|
|
110 |
}
|
|
|
111 |
} else {
|
|
|
112 |
System.out.println("No alerts were found.\n");
|
|
|
113 |
}
|
|
|
114 |
offset += PAGE_SIZE;
|
|
|
115 |
selector.getPaging().setStartIndex(offset);
|
|
|
116 |
} while (offset < page.getTotalNumEntries());
|
|
|
117 |
}
|
|
|
118 |
}
|