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.reporting;
16
 
17
import com.google.api.ads.adwords.axis.factory.AdWordsServices;
18
import com.google.api.ads.adwords.axis.v201309.cm.ReportDefinitionField;
19
import com.google.api.ads.adwords.axis.v201309.cm.ReportDefinitionReportType;
20
import com.google.api.ads.adwords.axis.v201309.cm.ReportDefinitionServiceInterface;
21
import com.google.api.ads.adwords.lib.client.AdWordsSession;
22
import com.google.api.ads.common.lib.auth.OfflineCredentials;
23
import com.google.api.ads.common.lib.auth.OfflineCredentials.Api;
24
import com.google.api.client.auth.oauth2.Credential;
25
 
26
/**
27
 * This example gets report fields.
28
 *
29
 * Credentials and properties in {@code fromFile()} are pulled from the
30
 * "ads.properties" file. See README for more info.
31
 *
32
 * Tags: ReportDefinitionService.getReportFields
33
 *
34
 * @author Kevin Winter
35
 */
36
public class GetReportFields {
37
 
38
  public static void main(String[] args) throws Exception {
39
    // Generate a refreshable OAuth2 credential similar to a ClientLogin token
40
    // and can be used in place of a service account.
41
    Credential oAuth2Credential = new OfflineCredentials.Builder()
42
        .forApi(Api.ADWORDS)
43
        .fromFile()
44
        .build()
45
        .generateCredential();
46
 
47
    // Construct an AdWordsSession.
48
    AdWordsSession session = new AdWordsSession.Builder()
49
        .fromFile()
50
        .withOAuth2Credential(oAuth2Credential)
51
        .build();
52
 
53
    AdWordsServices adWordsServices = new AdWordsServices();
54
 
55
    runExample(adWordsServices, session);
56
  }
57
 
58
  public static void runExample(
59
      AdWordsServices adWordsServices, AdWordsSession session) throws Exception {
60
    // Get the ReportDefinitionService.
61
    ReportDefinitionServiceInterface reportDefinitionService =
62
        adWordsServices.get(session, ReportDefinitionServiceInterface.class);
63
 
64
    // Get report fields.
65
    ReportDefinitionField[] reportDefinitionFields =
66
        reportDefinitionService
67
            .getReportFields(ReportDefinitionReportType.KEYWORDS_PERFORMANCE_REPORT);
68
 
69
    // Display report fields.
70
    System.out.println("Available fields for report:");
71
 
72
    for (ReportDefinitionField reportDefinitionField : reportDefinitionFields) {
73
      System.out.print("\t" + reportDefinitionField.getFieldName() + "("
74
          + reportDefinitionField.getFieldType() + ") := [");
75
      if (reportDefinitionField.getEnumValues() != null) {
76
        for (String enumValue : reportDefinitionField.getEnumValues()) {
77
          System.out.print(enumValue + ", ");
78
        }
79
      }
80
      System.out.println("]");
81
    }
82
  }
83
}