| 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.v201309.advancedoperations;
|
|
|
16 |
|
|
|
17 |
import com.google.api.ads.adwords.axis.factory.AdWordsServices;
|
|
|
18 |
import com.google.api.ads.adwords.axis.v201309.cm.AdGroupBidModifier;
|
|
|
19 |
import com.google.api.ads.adwords.axis.v201309.cm.AdGroupBidModifierOperation;
|
|
|
20 |
import com.google.api.ads.adwords.axis.v201309.cm.AdGroupBidModifierReturnValue;
|
|
|
21 |
import com.google.api.ads.adwords.axis.v201309.cm.AdGroupBidModifierServiceInterface;
|
|
|
22 |
import com.google.api.ads.adwords.axis.v201309.cm.Operator;
|
|
|
23 |
import com.google.api.ads.adwords.axis.v201309.cm.Platform;
|
|
|
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 illustrates how to add ad group level mobile bid modifier override for a 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.mutate
|
|
|
36 |
*
|
|
|
37 |
* @author Takeshi Hagikura
|
|
|
38 |
*/
|
|
|
39 |
public class AddAdGroupBidModifier {
|
|
|
40 |
|
|
|
41 |
private static final double BID_MODIFIER = 1.5;
|
|
|
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 |
Long adGroupId = Long.valueOf("INSERT_ADGROUP_ID_HERE");
|
|
|
59 |
|
|
|
60 |
AdWordsServices adWordsServices = new AdWordsServices();
|
|
|
61 |
|
|
|
62 |
runExample(adWordsServices, session, adGroupId);
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
public static void runExample(AdWordsServices adWordsServices, AdWordsSession session,
|
|
|
66 |
Long adGroupId) throws Exception {
|
|
|
67 |
// Get the AdGroupBidModifierService.
|
|
|
68 |
AdGroupBidModifierServiceInterface adGroupBidModifierService =
|
|
|
69 |
adWordsServices.get(session, AdGroupBidModifierServiceInterface.class);
|
|
|
70 |
|
|
|
71 |
// Create mobile platform. The ID can be found in the documentation.
|
|
|
72 |
// https://developers.google.com/adwords/api/docs/appendix/platforms
|
|
|
73 |
Platform mobile = new Platform();
|
|
|
74 |
mobile.setId(30001L);
|
|
|
75 |
|
|
|
76 |
AdGroupBidModifier adGroupBidModifier = new AdGroupBidModifier();
|
|
|
77 |
adGroupBidModifier.setAdGroupId(adGroupId);
|
|
|
78 |
adGroupBidModifier.setBidModifier(BID_MODIFIER);
|
|
|
79 |
adGroupBidModifier.setCriterion(mobile);
|
|
|
80 |
|
|
|
81 |
// Create ADD operation.
|
|
|
82 |
AdGroupBidModifierOperation operation = new AdGroupBidModifierOperation();
|
|
|
83 |
operation.setOperand(adGroupBidModifier);
|
|
|
84 |
// Use 'ADD' to add a new modifier and 'SET' to update an existing one. A
|
|
|
85 |
// modifier can be removed with the 'REMOVE' operator.
|
|
|
86 |
operation.setOperator(Operator.ADD);
|
|
|
87 |
|
|
|
88 |
// Update ad group bid modifier.
|
|
|
89 |
AdGroupBidModifierReturnValue result =
|
|
|
90 |
adGroupBidModifierService.mutate(new AdGroupBidModifierOperation[] {operation});
|
|
|
91 |
for (AdGroupBidModifier bidModifierResult : result.getValue()) {
|
|
|
92 |
System.out.printf(
|
|
|
93 |
"Campaign ID '%d', AdGroup ID '%d' was updated with ad group level modifier: %.2f\n",
|
|
|
94 |
bidModifierResult.getCampaignId(), bidModifierResult.getAdGroupId(),
|
|
|
95 |
bidModifierResult.getBidModifier());
|
|
|
96 |
}
|
|
|
97 |
}
|
|
|
98 |
}
|