为什么Java不允许我在这里使用OAuth2Native方法?

时间:2013-06-23 14:35:34

标签: java google-analytics oauth-2.0 google-analytics-api google-oauth

好的,所以我正在尝试构建一个简单的“Hello World”类型程序,该程序从Google AnalyticsAPI获取数据。我在这里遵循教程:

https://developers.google.com/analytics/solutions/articles/hello-analytics-api

我的代码如下。还没有主要的方法,我只是想获得授权并设置一个Analytics服务对象。我在Netbeans工作。我已从代码顶部列出的Google下载了导入的类。我的问题是Netbeans在initializeAnalytics的第一行OAuth2Native.authorize()Analytics.builder()下面几行给我一个“找不到符号”。我假设我需要导入一些类,但我似乎无法找到它并想​​知道这根本不是问题。

非常感谢提前。

package helloanalyticsapi;

import com.google.api.client.auth.oauth2.*;
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
import com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAccessProtectedResource;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson.JacksonFactory;
import com.google.api.services.analytics.Analytics;
import com.google.api.services.analytics.AnalyticsScopes;
import java.util.Arrays;

public class HelloAnalyticsApi {

 // Global instance of the HTTP transport.
 private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();

 // Global instance of the JSON factory.
 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 = Analytics.builder(HTTP_TRANSPORT, JSON_FACTORY)
        .setApplicationName("Hello-Analytics-API-Sample")
        .setHttpRequestInitializer(credential)
        .build();

    return analytics;

 }

 public static void main(String[] args) {   

 }
}

0 个答案:

没有答案