7

我正在尝试从https://developers.google.com/analytics/solutions/articles/hello-analytics-api运行一个简单的示例来访问 Google 分析数据。

google-api-java-client-1.17.0-rc.ziphttps://code.google.com/p/google-api-java-client/downloads/list下载了 java api-library ,

有示例代码显示编译错误:

    private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();

    private static final JsonFactory JSON_FACTORY = new JacksonFactory();

    private static Analytics initializeAnalytics() throws Exception {
        Credential credential = OAuth2Native.authorize(
        HTTP_TRANSPORT, JSON_FACTORY, new LocalServerReceiver(),
        Arrays.asList(AnalyticsScopes.ANALYTICS_READONLY));

        Analytics analytics = Analytics.builder(HTTP_TRANSPORT, JSON_FACTORY)
  .setApplicationName("Hello-Analytics-API-Sample")
  .setHttpRequestInitializer(credential)
  .build();

我在类路径中添加了所有库,但库似乎没有一些类:

OAuth2Native

AnalyticsScopes

Analytics

但是这些课程出现在http://code.google.com/p/google-api-java-client/source/browse/shared/shared-sample-cmdline/src/main/java/com/google/api/services/samples/shared/cmdline/oauth2/OAuth2Native.java?repo=samples&r=89662bd8ab341647b3f0aab8ed6a4fb444f478c2

4

1 回答 1

1

我建议从以下链接下载源代码

hg clone https://code.google.com/p/google-api-java-client.samples/

您必须使用mercurial才能签出项目。下载后,一切运行顺利,它还向您展示了授权实施的示例。它没有依赖性问题。

于 2015-01-03T02:48:17.977 回答