如何使用java获取谷歌分析数据?

时间:2016-07-08 13:47:11

标签: java google-api google-analytics-api google-authentication

我正在尝试使用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();
    }
  }

enter image description here

1 个答案:

答案 0 :(得分:0)

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

你可以在那里查看我的代码。 我不要只检查第一个帐户的第一个webproperty的第一个配置文件。我检查它们,导致更多更好。