Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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.v201306.campaignmanagement;
16
 
17
import com.google.api.ads.adwords.axis.factory.AdWordsServices;
18
import com.google.api.ads.adwords.axis.v201306.cm.Experiment;
19
import com.google.api.ads.adwords.axis.v201306.cm.ExperimentOperation;
20
import com.google.api.ads.adwords.axis.v201306.cm.ExperimentReturnValue;
21
import com.google.api.ads.adwords.axis.v201306.cm.ExperimentServiceInterface;
22
import com.google.api.ads.adwords.axis.v201306.cm.ExperimentStatus;
23
import com.google.api.ads.adwords.axis.v201306.cm.Operator;
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 promotes an experiment, which permanently applies all the
31
 * experimental changes made to its related ad groups, criteria and ads. To get
32
 * experiments, run AddExperiment.java. To add an experiment, run
33
 * AddExperiment.java.
34
 *
35
 * Credentials and properties in {@code fromFile()} are pulled from the
36
 * "ads.properties" file. See README for more info.
37
 *
38
 * Tags: ExperimentService.mutate
39
 *
40
 * Category: adx-exclude
41
 *
42
 * @author Kevin Winter
43
 */
44
public class PromoteExperiment {
45
 
46
  public static void main(String[] args) throws Exception {
47
    // Generate a refreshable OAuth2 credential similar to a ClientLogin token
48
    // and can be used in place of a service account.
49
    Credential oAuth2Credential = new OfflineCredentials.Builder()
50
        .forApi(Api.ADWORDS)
51
        .fromFile()
52
        .build()
53
        .generateCredential();
54
 
55
    // Construct an AdWordsSession.
56
    AdWordsSession session = new AdWordsSession.Builder()
57
        .fromFile()
58
        .withOAuth2Credential(oAuth2Credential)
59
        .build();
60
 
61
    long experimentId = Long.parseLong("INSERT_EXPERIMENT_ID_HERE");
62
 
63
    AdWordsServices adWordsServices = new AdWordsServices();
64
 
65
    runExample(adWordsServices, session, experimentId);
66
  }
67
 
68
  public static void runExample(
69
      AdWordsServices adWordsServices, AdWordsSession session, Long experimentId) throws Exception {
70
    // Get the ExperimentService.
71
    ExperimentServiceInterface experimentService =
72
        adWordsServices.get(session, ExperimentServiceInterface.class);
73
 
74
    // Create experiment with PROMOTED status.
75
    Experiment experiment = new Experiment();
76
    experiment.setId(experimentId);
77
    experiment.setStatus(ExperimentStatus.PROMOTED);
78
 
79
    // Create operation.
80
    ExperimentOperation operation = new ExperimentOperation();
81
    operation.setOperand(experiment);
82
    operation.setOperator(Operator.SET);
83
 
84
    ExperimentOperation[] operations = new ExperimentOperation[] {operation};
85
 
86
    // Promote experiment.
87
    ExperimentReturnValue result = experimentService.mutate(operations);
88
 
89
    // Display experiments.
90
    for (Experiment experimentResult : result.getValue()) {
91
      System.out.println("Experiment with name \"" + experimentResult.getName() + "\" and id \""
92
          + experimentResult.getId() + "\" was promoted.");
93
    }
94
  }
95
}