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.adwordsforvideo;
16
 
17
import com.google.api.ads.adwords.axis.factory.AdWordsServices;
18
import com.google.api.ads.adwords.axis.v201302.cm.Paging;
19
import com.google.api.ads.adwords.axis.v201302.video.NegativeVideoCampaignCriterion;
20
import com.google.api.ads.adwords.axis.v201302.video.VideoCampaignCriterion;
21
import com.google.api.ads.adwords.axis.v201302.video.VideoCampaignCriterionPage;
22
import com.google.api.ads.adwords.axis.v201302.video.VideoCampaignCriterionSelector;
23
import com.google.api.ads.adwords.axis.v201302.video.VideoCampaignCriterionServiceInterface;
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 demonstrates how to retrieve all campaign-level criteria in a
31
 * campaign.
32
 *
33
 * Credentials and properties in {@code fromFile()} are pulled from the
34
 * "ads.properties" file. See README for more info.
35
 *
36
 * Tags: VideoCampaignCriterionService.get
37
 *
38
 * Category: adx-exclude
39
 *
40
 * @author Kevin Winter
41
 */
42
public class GetVideoCampaignCriteria {
43
 
44
  private static final int PAGE_SIZE = 100;
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 campaignId = Long.parseLong("INSERT_CAMPAIGN_ID_HERE");
62
 
63
    AdWordsServices adWordsServices = new AdWordsServices();
64
 
65
    runExample(adWordsServices, session, campaignId);
66
  }
67
 
68
  public static void runExample(
69
      AdWordsServices adWordsServices, AdWordsSession session, Long campaignId) throws Exception {
70
    // Get the VideoCampaignCriterionService.
71
    VideoCampaignCriterionServiceInterface videoCampaignCriterionService =
72
        adWordsServices.get(session, VideoCampaignCriterionServiceInterface.class);
73
 
74
    int offset = 0;
75
    boolean morePages = true;
76
 
77
    // Create selector.
78
    VideoCampaignCriterionSelector selector = new VideoCampaignCriterionSelector();
79
    selector.setCampaignIds(new long[] {campaignId});
80
    selector.setPaging(new Paging(offset, PAGE_SIZE));
81
 
82
    while (morePages) {
83
      // Get all criteria for the campaign.
84
      VideoCampaignCriterionPage page = videoCampaignCriterionService.get(selector);
85
 
86
      // Display criteria.
87
      if (page.getEntries() != null) {
88
        for (VideoCampaignCriterion videoCampaignCriterion : page.getEntries()) {
89
          String negative =
90
              (videoCampaignCriterion instanceof NegativeVideoCampaignCriterion) ? " (negative)"
91
                  : "";
92
          System.out.printf("Video%s criterion ID %d of type '%s'\n", negative,
93
              videoCampaignCriterion.getCriterion().getId(),
94
              videoCampaignCriterion.getCriterion().getBaseCriterionType());
95
        }
96
      } else {
97
        System.out.println("No criteria were found.");
98
      }
99
 
100
      offset += PAGE_SIZE;
101
      selector.getPaging().setStartIndex(offset);
102
      morePages = offset < page.getTotalNumEntries();
103
    }
104
  }
105
}