如何使用java获取谷歌分析数据? [英] How to get google analytics data using java?

查看:221
本文介绍了如何使用java获取谷歌分析数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用java下载谷歌分析数据。我正在使用Google开发者指南提供的快速入门代码。我从开发者控制台下载了json格式的oauth凭证文件。我也给了程序的json路径,但我得到错误。请帮助

  public class HelloAnalytics {
//从开发者控制台下载的client_secrets.json文件的路径。
//路径相对于HelloAnalytics.java。
private static final String CLIENT_SECRET_JSON_RESOURCE =ga-data-report-7ac3499541bf.json;

//用户凭据的存储目录。
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();
}
}



您可以查看我的代码aswel。
我不只是检查第一个帐户的第一个webproperty的第一个配置文件。我检查他们全部,原因越多越好。


I am trying to download a google analytics data using java. I am using a quick start code provided by google developer guide. I downloaded oauth credential file in json format from the developer console. I also given the json path to program but I am getting error. Please help

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();
    }
  }

解决方案

I think the answer is on my post: Hello Analytics API: Java quickstart errors

You can check out my code there aswel. I Don't just check the first profile of the first webproperty of the first account. I check them all, cause more is better.

这篇关于如何使用java获取谷歌分析数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆