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.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.AdGroupBidModifierPage;
20
import com.google.api.ads.adwords.axis.v201309.cm.AdGroupBidModifierServiceInterface;
21
import com.google.api.ads.adwords.axis.v201309.cm.Paging;
22
import com.google.api.ads.adwords.axis.v201309.cm.Selector;
23
import com.google.api.ads.adwords.lib.client.AdWordsSession;
24
import com.google.api.ads.common.lib.auth.OfflineCredentials;
25
import com.google.api.ads.common.lib.auth.OfflineCredentials.Api;
26
import com.google.api.client.auth.oauth2.Credential;
27
 
28
/**
29
 * This example illustrates how to retrieve the first 10 ad group level bid modifiers.
30
 *
31
 * Credentials and properties in {@code fromFile()} are pulled from the "ads.properties" file. See
32
 * README for more info.
33
 *
34
 * Tags: AdGroupBidModifierService.get
35
 *
36
 * @author Takeshi Hagikura
37
 */
38
public class GetAdGroupBidModifier {
39
 
40
  private static final int PAGE_SIZE = 10;
41
 
42
  public static void main(String[] args) throws Exception {
43
    // Generate a refreshable OAuth2 credential similar to a ClientLogin token
44
    // and can be used in place of a service account.
45
    Credential oAuth2Credential = new OfflineCredentials.Builder()
46
        .forApi(Api.ADWORDS)
47
        .fromFile()
48
        .build()
49
        .generateCredential();
50
 
51
    // Construct an AdWordsSession.
52
    AdWordsSession session = new AdWordsSession.Builder()
53
        .fromFile()
54
        .withOAuth2Credential(oAuth2Credential)
55
        .build();
56
 
57
    AdWordsServices adWordsServices = new AdWordsServices();
58
 
59
    runExample(adWordsServices, session);
60
  }
61
 
62
  public static void runExample(AdWordsServices adWordsServices,
63
      AdWordsSession session) throws Exception {
64
    // Get the AdGroupBidModifierService.
65
    AdGroupBidModifierServiceInterface adGroupBidModifierService =
66
        adWordsServices.get(session, AdGroupBidModifierServiceInterface.class);
67
 
68
    int offset = 0;
69
 
70
    // Create selector.
71
    Selector selector = new Selector();
72
    selector.setFields(new String[] {"CampaignId",
73
        "AdGroupId",
74
        "BidModifier",
75
        "Id"});
76
    selector.setPaging(new Paging(offset, PAGE_SIZE));
77
 
78
    AdGroupBidModifierPage page = adGroupBidModifierService.get(selector);
79
    if (page.getEntries() != null) {
80
      for (AdGroupBidModifier bidModifierResult : page.getEntries()) {
81
        String bidModifierValue =
82
            bidModifierResult.getBidModifier() != null
83
                ? bidModifierResult.getBidModifier().toString()
84
                : "unset";
85
        System.out.printf("Campaign ID '%d', AdGroup ID '%d', Criterion ID '%d', "
86
            + "has ad group level modifier: '%s'\n",
87
            bidModifierResult.getCampaignId(),
88
            bidModifierResult.getAdGroupId(),
89
            bidModifierResult.getCriterion().getId(),
90
            bidModifierValue);
91
      }
92
    } else {
93
      System.out.println("No ad group level bid modifiers were found.");
94
    }
95
  }
96
}