Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

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