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.v201309.optimization;
16
 
17
import com.google.api.ads.adwords.axis.factory.AdWordsServices;
18
import com.google.api.ads.adwords.axis.v201309.cm.BidLandscapeLandscapePoint;
19
import com.google.api.ads.adwords.axis.v201309.cm.CriterionBidLandscape;
20
import com.google.api.ads.adwords.axis.v201309.cm.CriterionBidLandscapePage;
21
import com.google.api.ads.adwords.axis.v201309.cm.DataServiceInterface;
22
import com.google.api.ads.adwords.axis.v201309.cm.Predicate;
23
import com.google.api.ads.adwords.axis.v201309.cm.PredicateOperator;
24
import com.google.api.ads.adwords.axis.v201309.cm.Selector;
25
import com.google.api.ads.adwords.lib.client.AdWordsSession;
26
import com.google.api.ads.common.lib.auth.OfflineCredentials;
27
import com.google.api.ads.common.lib.auth.OfflineCredentials.Api;
28
import com.google.api.client.auth.oauth2.Credential;
29
 
30
/**
31
 * This example gets a bid landscape for an ad group and a criterion. To get ad
32
 * groups, run GetAdGroups.java. To get criteria, run GetKeywords.java.
33
 *
34
 * Credentials and properties in {@code fromFile()} are pulled from the
35
 * "ads.properties" file. See README for more info.
36
 *
37
 * Tags: DataService.get
38
 *
39
 * Category: adx-exclude
40
 *
41
 * @author Kevin Winter
42
 */
43
public class GetKeywordBidSimulations {
44
 
45
  public static void main(String[] args) throws Exception {
46
    // Generate a refreshable OAuth2 credential similar to a ClientLogin token
47
    // and can be used in place of a service account.
48
    Credential oAuth2Credential = new OfflineCredentials.Builder()
49
        .forApi(Api.ADWORDS)
50
        .fromFile()
51
        .build()
52
        .generateCredential();
53
 
54
    // Construct an AdWordsSession.
55
    AdWordsSession session = new AdWordsSession.Builder()
56
        .fromFile()
57
        .withOAuth2Credential(oAuth2Credential)
58
        .build();
59
 
60
    Long adGroupId = Long.parseLong("INSERT_AD_GROUP_ID_HERE");
61
    Long criterionId = Long.parseLong("INSERT_CRITERION_ID_HERE");
62
 
63
    AdWordsServices adWordsServices = new AdWordsServices();
64
 
65
    runExample(adWordsServices, session, adGroupId, criterionId);
66
  }
67
 
68
  public static void runExample(
69
      AdWordsServices adWordsServices, AdWordsSession session, Long adGroupId,
70
      Long criterionId) throws Exception {
71
    // Get the DataService.
72
    DataServiceInterface dataService =
73
        adWordsServices.get(session, DataServiceInterface.class);
74
 
75
    // Create selector.
76
    Selector selector = new Selector();
77
    selector.setFields(new String[] {"AdGroupId", "CriterionId", "StartDate", "EndDate", "Bid",
78
        "LocalClicks", "LocalCost", "MarginalCpc", "LocalImpressions"});
79
 
80
    // Create predicates.
81
    Predicate adGroupIdPredicate =
82
        new Predicate("AdGroupId", PredicateOperator.IN, new String[] {adGroupId.toString()});
83
    Predicate criterionIdPredicate =
84
        new Predicate("CriterionId", PredicateOperator.IN, new String[] {criterionId.toString()});
85
    selector.setPredicates(new Predicate[] {adGroupIdPredicate, criterionIdPredicate});
86
 
87
    // Get bid landscape for ad group criteria.
88
    CriterionBidLandscapePage page = dataService.getCriterionBidLandscape(selector);
89
 
90
    // Display bid landscapes.
91
    if (page.getEntries() != null) {
92
      for (CriterionBidLandscape criterionBidLandscape : page.getEntries()) {
93
        System.out.println("Criterion bid landscape with ad group id \""
94
            + criterionBidLandscape.getAdGroupId() + "\", criterion id \""
95
            + criterionBidLandscape.getCriterionId() + "\", start date \""
96
            + criterionBidLandscape.getStartDate() + "\", end date \""
97
            + criterionBidLandscape.getEndDate() + "\", with landscape points: ");
98
 
99
        for (BidLandscapeLandscapePoint bidLanscapePoint : criterionBidLandscape
100
            .getLandscapePoints()) {
101
          System.out.println("\t{bid: " + bidLanscapePoint.getBid().getMicroAmount() + " clicks: "
102
              + bidLanscapePoint.getClicks() + " cost: "
103
              + bidLanscapePoint.getCost().getMicroAmount() + " marginalCpc: "
104
              + bidLanscapePoint.getMarginalCpc().getMicroAmount() + " impressions: "
105
              + bidLanscapePoint.getImpressions() + "}");
106
        }
107
        System.out.println(" was found.");
108
      }
109
    } else {
110
      System.out.println("No criterion bid landscapes were found.");
111
    }
112
  }
113
}