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.v201309.campaignmanagement;
16
 
17
import com.google.api.ads.adwords.axis.factory.AdWordsServices;
18
import com.google.api.ads.adwords.axis.v201309.cm.CampaignCriterion;
19
import com.google.api.ads.adwords.axis.v201309.cm.CampaignCriterionOperation;
20
import com.google.api.ads.adwords.axis.v201309.cm.CampaignCriterionReturnValue;
21
import com.google.api.ads.adwords.axis.v201309.cm.CampaignCriterionServiceInterface;
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 sets a bid modifier for the mobile platform on given campaign.
31
 * To get campaigns, run basicoperations/GetCampaigns.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: CampaignCriterionService.mutate
37
 *
38
 * @author Kevin Winter
39
 */
40
public class SetBidModifier {
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 campaignId = Long.valueOf("INSERT_CAMPAIGN_ID_HERE");
60
 
61
    AdWordsServices adWordsServices = new AdWordsServices();
62
 
63
    runExample(adWordsServices, session, campaignId);
64
  }
65
 
66
  public static void runExample(
67
      AdWordsServices adWordsServices, AdWordsSession session, Long campaignId) throws Exception {
68
    // Get the CampaignCriterionService.
69
    CampaignCriterionServiceInterface campaignCriterionService =
70
        adWordsServices.get(session, CampaignCriterionServiceInterface.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
    // Create criterion with modified bid.
78
    CampaignCriterion campaignCriterion = new CampaignCriterion();
79
    campaignCriterion.setCampaignId(campaignId);
80
    campaignCriterion.setCriterion(mobile);
81
    campaignCriterion.setBidModifier(BID_MODIFIER);
82
 
83
    // Create SET operation.
84
    CampaignCriterionOperation operation = new CampaignCriterionOperation();
85
    operation.setOperand(campaignCriterion);
86
    operation.setOperator(Operator.SET);
87
 
88
    // Update campaign criterion.
89
    CampaignCriterionReturnValue result =
90
        campaignCriterionService.mutate(new CampaignCriterionOperation[] {operation});
91
    for (CampaignCriterion campaignCriterionResult : result.getValue()) {
92
      System.out.printf("Campaign criterion with campaign id '%s', criterion id '%s', "
93
          + "and type '%s' was modified with bid %.2f.\n",
94
          campaignCriterionResult.getCampaignId(),
95
          campaignCriterionResult.getCriterion().getId(),
96
          campaignCriterionResult.getCriterion().getType(),
97
          campaignCriterionResult.getBidModifier());
98
    }
99
  }
100
}