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.VideoCampaign;
20
import com.google.api.ads.adwords.axis.v201302.video.VideoCampaignPage;
21
import com.google.api.ads.adwords.axis.v201302.video.VideoCampaignSelector;
22
import com.google.api.ads.adwords.axis.v201302.video.VideoCampaignServiceInterface;
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 all non-deleted video campaigns for
30
 * an account.
31
 *
32
 * Credentials and properties in {@code fromFile()} are pulled from the
33
 * "ads.properties" file. See README for more info.
34
 *
35
 * Tags: VideoCampaignService.get
36
 *
37
 * Category: adx-exclude
38
 *
39
 * @author Kevin Winter
40
 */
41
public class GetVideoCampaigns {
42
 
43
  private static final int PAGE_SIZE = 100;
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
    AdWordsServices adWordsServices = new AdWordsServices();
61
 
62
    runExample(adWordsServices, session);
63
  }
64
 
65
  public static void runExample(
66
      AdWordsServices adWordsServices, AdWordsSession session) throws Exception {
67
    // Get the VideoCampaignService.
68
    VideoCampaignServiceInterface videoCampaignService =
69
        adWordsServices.get(session, VideoCampaignServiceInterface.class);
70
 
71
    int offset = 0;
72
    boolean morePages = true;
73
 
74
    // Create selector.
75
    VideoCampaignSelector selector = new VideoCampaignSelector();
76
    selector.setPaging(new Paging(offset, PAGE_SIZE));
77
 
78
    while (morePages) {
79
      // Get all targeting groups for this account.
80
      VideoCampaignPage page = videoCampaignService.get(selector);
81
 
82
      // Display targeting groups.
83
      if (page.getEntries() != null) {
84
        for (VideoCampaign videoCampaign : page.getEntries()) {
85
          System.out.printf("Campaign ID %d, name '%s' and status '%s'\n", videoCampaign.getId(),
86
              videoCampaign.getName(), videoCampaign.getStatus());
87
        }
88
      } else {
89
        System.out.println("No targeting groups were found.");
90
      }
91
 
92
      offset += PAGE_SIZE;
93
      selector.getPaging().setStartIndex(offset);
94
      morePages = offset < page.getTotalNumEntries();
95
    }
96
  }
97
}