【发布时间】:2016-07-08 13:47:11
【问题描述】:
我正在尝试使用 java 下载谷歌分析数据。我正在使用谷歌开发者指南提供的快速启动代码。我从开发者控制台下载了 json 格式的 oauth 凭证文件。我还给出了程序的 json 路径,但出现错误。请帮忙
public class HelloAnalytics {
// Path to client_secrets.json file downloaded from the Developer's Console.
// The path is relative to HelloAnalytics.java.
private static final String CLIENT_SECRET_JSON_RESOURCE = "ga-data-report-7ac3499541bf.json";
// The directory where the user's credentials will be stored.
private static final File DATA_STORE_DIR = new File(
System.getProperty("user.home"), "store/hello_analytics");
private static final String APPLICATION_NAME = "Hello Analytics";
private static final JsonFactory JSON_FACTORY = GsonFactory.getDefaultInstance();
private static NetHttpTransport httpTransport;
private static FileDataStoreFactory dataStoreFactory;
public static void main(String[] args) {
try {
Analytics analytics = initializeAnalytics();
String profile = getFirstProfileId(analytics);
printResults(getResults(analytics, profile));
} catch (Exception e) {
e.printStackTrace();
}
}
【问题讨论】:
-
你在第 65 行得到一个 NullPoinerException。你在第 65 行有什么?是 getResults() 返回 null 吗?
-
第 65 行是 printResults(getResults(analytics, profile));
-
我是这么认为的。检查分析或配置文件是否为 null 或 getResults 返回 null。最好是发布minimal reproducible example
-
检查视图是否有您正在制作的request 的数据。客户端库可能不会实例化一个空对象,
printResults()可能会假设getRows()返回一些东西。
标签: java google-api google-analytics-api google-authentication