Skip to content
This repository was archived by the owner on Feb 18, 2024. It is now read-only.

Commit 3072dfd

Browse files
author
Joseph DiLallo
committed
Updating DFA Reporting API examples for v1.3 https://codereview.appspot.com/11577043/
1 parent 051a7d4 commit 3072dfd

File tree

4 files changed

+96
-18
lines changed

4 files changed

+96
-18
lines changed

dfareporting-cmdline-sample/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
<dependency>
110110
<groupId>com.google.apis</groupId>
111111
<artifactId>google-api-services-dfareporting</artifactId>
112-
<version>v1.2-rev4-1.16.0-rc</version>
112+
<version>v1.3-rev3-1.16.0-rc</version>
113113
</dependency>
114114
<dependency>
115115
<groupId>com.google.http-client</groupId>

dfareporting-cmdline-sample/src/main/java/com/google/api/services/samples/dfareporting/cmdline/DfaReportingSample.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,9 @@ public class DfaReportingSample {
6666
* globally shared instance across your application.
6767
*/
6868
private static FileDataStoreFactory DATA_STORE_FACTORY;
69-
69+
7070
private static final List<String> SCOPES = ImmutableList.of(
71-
"https://www.googleapis.com/auth/dfareporting",
72-
"https://www.googleapis.com/auth/devstorage.read_only");
71+
"https://www.googleapis.com/auth/dfareporting");
7372

7473
private static HttpTransport TRANSPORT;
7574
private static final JsonFactory JSON_FACTORY = new JacksonFactory();
@@ -145,6 +144,7 @@ public static void main(String[] args) {
145144

146145
Report standardReport = CreateStandardReport.insert(reporting, userProfileId,
147146
advertiser, startDate, endDate);
147+
GetCompatibleFields.run(reporting, userProfileId, standardReport);
148148
File file = GenerateReportFile.run(reporting, userProfileId, standardReport, true);
149149

150150
if (file != null) {

dfareporting-cmdline-sample/src/main/java/com/google/api/services/samples/dfareporting/cmdline/DownloadReportFile.java

+14-14
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414

1515
package com.google.api.services.samples.dfareporting.cmdline;
1616

17-
import com.google.api.client.http.GenericUrl;
18-
import com.google.api.client.http.HttpRequest;
19-
import com.google.api.client.http.HttpRequestFactory;
2017
import com.google.api.client.http.HttpResponse;
2118
import com.google.api.client.util.Charsets;
2219
import com.google.api.services.dfareporting.Dfareporting;
@@ -33,7 +30,7 @@
3330
public class DownloadReportFile {
3431

3532
/**
36-
* Fetchs the contents of a report file.
33+
* Fetches the contents of a report file.
3734
*
3835
* @param reporting Dfareporting service object on which to run the requests.
3936
* @param reportFile The completed report file to download.
@@ -47,16 +44,19 @@ public static void run(Dfareporting reporting, File reportFile)
4744
System.out.printf("The ID number of this report file is %s%n", reportFile.getId());
4845
System.out.println("=================================================================");
4946

50-
String url = reportFile.getUrls().getApiUrl();
51-
GenericUrl genericUrl = new GenericUrl(url);
52-
HttpRequestFactory httpRequestFactory = reporting.getRequestFactory();
53-
HttpRequest httpRequest = httpRequestFactory.buildGetRequest(genericUrl);
54-
HttpResponse response = httpRequest.execute();
55-
BufferedReader reader = new BufferedReader(
56-
new InputStreamReader(response.getContent(), Charsets.UTF_8));
57-
String line;
58-
while ((line = reader.readLine()) != null) {
59-
System.out.println(line);
47+
HttpResponse fileContents = reporting.files()
48+
.get(reportFile.getReportId(), reportFile.getId())
49+
.executeMedia();
50+
51+
try {
52+
BufferedReader reader = new BufferedReader(
53+
new InputStreamReader(fileContents.getContent(), Charsets.UTF_8));
54+
String line;
55+
while ((line = reader.readLine()) != null) {
56+
System.out.println(line);
57+
}
58+
} finally {
59+
fileContents.disconnect();
6060
}
6161
}
6262
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright (c) 2013 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. 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 distributed under the License
10+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the License for the specific language governing permissions and limitations under
12+
* the License.
13+
*/
14+
15+
package com.google.api.services.samples.dfareporting.cmdline;
16+
17+
import com.google.api.services.dfareporting.Dfareporting;
18+
import com.google.api.services.dfareporting.model.CompatibleFields;
19+
import com.google.api.services.dfareporting.model.Dimension;
20+
import com.google.api.services.dfareporting.model.Metric;
21+
import com.google.api.services.dfareporting.model.Report;
22+
import com.google.api.services.dfareporting.model.ReportCompatibleFields;
23+
24+
/**
25+
* This example fetches and displays the compatible fields for the given standard report. There
26+
* are two reasons why metrics and/or dimensions may be incompatible with your report:
27+
*
28+
* <ul><li>Your user profile doesn't have permission to view those fields</li>
29+
* <li>Your report contains a field which is incompatible with certain other fields</li></ul>
30+
*
31+
* Tags: compatibleFields.query
32+
*
33+
* @author [email protected] (Joseph DiLallo)
34+
*/
35+
public class GetCompatibleFields {
36+
37+
/**
38+
* Fetches and displays the compatible fields for the given standard report.
39+
*
40+
* @param reporting Dfareporting service object on which to run the requests.
41+
* @param userProfileId The ID number of the DFA user profile to run this request as.
42+
* @param report Displays additional fields compatible with this report.
43+
*/
44+
public static void run(Dfareporting reporting, Long userProfileId, Report report)
45+
throws Exception {
46+
System.out.println("=================================================================");
47+
System.out.printf("Getting compatible fields for standard report with ID %s%n",
48+
report.getId());
49+
System.out.println("=================================================================");
50+
51+
CompatibleFields compatibleFields = reporting.reports().compatibleFields()
52+
.query(userProfileId, report).execute();
53+
54+
// Since this is a standard report, we check the "reportCompatibleFields" property.
55+
// For other reports, we would check that report type's specific property.
56+
ReportCompatibleFields standardReportCompatibleFields =
57+
compatibleFields.getReportCompatibleFields();
58+
59+
for (Dimension compatibleDimension : standardReportCompatibleFields.getDimensions()) {
60+
System.out.printf("Dimension \"%s\" is compatible.%n", compatibleDimension.getName());
61+
}
62+
63+
for (Metric compatibleMetric : standardReportCompatibleFields.getMetrics()) {
64+
System.out.printf("Metric \"%s\" is compatible.%n", compatibleMetric.getName());
65+
}
66+
67+
for (Dimension compatibleDimension : standardReportCompatibleFields.getDimensionFilters()) {
68+
System.out.printf("Dimension Filter \"%s\" is compatible.%n", compatibleDimension.getName());
69+
}
70+
71+
for (Metric compatibleMetric : standardReportCompatibleFields.getPivotedActivityMetrics()) {
72+
System.out.printf("Pivoted Activity Metric \"%s\" is compatible.%n",
73+
compatibleMetric.getName());
74+
}
75+
76+
System.out.println();
77+
}
78+
}

0 commit comments

Comments
 (0)