| 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.advancedoperations;
|
|
|
16 |
|
|
|
17 |
import com.google.api.ads.adwords.axis.factory.AdWordsServices;
|
|
|
18 |
import com.google.api.ads.adwords.axis.v201302.cm.AdGroupBidModifier;
|
|
|
19 |
import com.google.api.ads.adwords.axis.v201302.cm.AdGroupBidModifierPage;
|
|
|
20 |
import com.google.api.ads.adwords.axis.v201302.cm.AdGroupBidModifierServiceInterface;
|
|
|
21 |
import com.google.api.ads.adwords.axis.v201302.cm.Paging;
|
|
|
22 |
import com.google.api.ads.adwords.axis.v201302.cm.Selector;
|
|
|
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 |
/**
|
|
|
29 |
* This example illustrates how to retrieve the first 10 ad group level bid modifiers.
|
|
|
30 |
* NOTE: the campaign must be an enhanced campaign.
|
|
|
31 |
*
|
|
|
32 |
* Credentials and properties in {@code fromFile()} are pulled from the "ads.properties" file. See
|
|
|
33 |
* README for more info.
|
|
|
34 |
*
|
|
|
35 |
* Tags: AdGroupBidModifierService.get
|
|
|
36 |
*
|
|
|
37 |
* @author Takeshi Hagikura
|
|
|
38 |
*/
|
|
|
39 |
public class GetAdGroupBidModifier {
|
|
|
40 |
|
|
|
41 |
private static final int PAGE_SIZE = 10;
|
|
|
42 |
|
|
|
43 |
public static void main(String[] args) throws Exception {
|
|
|
44 |
// Generate a refreshable OAuth2 credential similar to a ClientLogin token
|
|
|
45 |
// and can be used in place of a service account.
|
|
|
46 |
Credential oAuth2Credential = new OfflineCredentials.Builder()
|
|
|
47 |
.forApi(Api.ADWORDS)
|
|
|
48 |
.fromFile()
|
|
|
49 |
.build()
|
|
|
50 |
.generateCredential();
|
|
|
51 |
|
|
|
52 |
// Construct an AdWordsSession.
|
|
|
53 |
AdWordsSession session = new AdWordsSession.Builder()
|
|
|
54 |
.fromFile()
|
|
|
55 |
.withOAuth2Credential(oAuth2Credential)
|
|
|
56 |
.build();
|
|
|
57 |
|
|
|
58 |
AdWordsServices adWordsServices = new AdWordsServices();
|
|
|
59 |
|
|
|
60 |
runExample(adWordsServices, session);
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
public static void runExample(AdWordsServices adWordsServices,
|
|
|
64 |
AdWordsSession session) throws Exception {
|
|
|
65 |
// Get the AdGroupBidModifierService.
|
|
|
66 |
AdGroupBidModifierServiceInterface adGroupBidModifierService =
|
|
|
67 |
adWordsServices.get(session, AdGroupBidModifierServiceInterface.class);
|
|
|
68 |
|
|
|
69 |
int offset = 0;
|
|
|
70 |
|
|
|
71 |
// Create selector.
|
|
|
72 |
Selector selector = new Selector();
|
|
|
73 |
selector.setFields(new String[] {"CampaignId",
|
|
|
74 |
"AdGroupId",
|
|
|
75 |
"BidModifier",
|
|
|
76 |
"Id"});
|
|
|
77 |
selector.setPaging(new Paging(offset, PAGE_SIZE));
|
|
|
78 |
|
|
|
79 |
AdGroupBidModifierPage page = adGroupBidModifierService.get(selector);
|
|
|
80 |
if (page.getEntries() != null) {
|
|
|
81 |
for (AdGroupBidModifier bidModifierResult : page.getEntries()) {
|
|
|
82 |
String bidModifierValue =
|
|
|
83 |
bidModifierResult.getBidModifier() != null
|
|
|
84 |
? bidModifierResult.getBidModifier().toString()
|
|
|
85 |
: "unset";
|
|
|
86 |
System.out.printf("Campaign ID '%d', AdGroup ID '%d', Criterion ID '%d', "
|
|
|
87 |
+ "has ad group level modifier: '%s'\n",
|
|
|
88 |
bidModifierResult.getCampaignId(),
|
|
|
89 |
bidModifierResult.getAdGroupId(),
|
|
|
90 |
bidModifierResult.getCriterion().getId(),
|
|
|
91 |
bidModifierValue);
|
|
|
92 |
}
|
|
|
93 |
} else {
|
|
|
94 |
System.out.println("No ad group level bid modifiers were found.");
|
|
|
95 |
}
|
|
|
96 |
}
|
|
|
97 |
}
|