【问题标题】:How to get google analytics data using java?如何使用java获取谷歌分析数据?
【发布时间】: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


【解决方案1】:

我认为答案在我的帖子中:Hello Analytics API: Java quickstart errors

您也可以在那里查看我的代码。 我不只是检查第一个帐户的第一个网络资产的第一个配置文件。我都检查了,因为越多越好。

【讨论】:

    猜你喜欢
    • 2022-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多