好的,所以我正在尝试构建一个简单的“Hello World”类型的程序,从 Google Analytics API 获取数据。我在这里学习教程:
https://developers.google.com/analytics/solutions/articles/hello-analytics-api
我的代码如下。还没有主要方法,我只是想获得授权并设置分析服务对象。我在 Netbeans 工作。我已经下载了代码顶部列出的从 Google 导入的类。OAuth2Native.authorize()
我的问题是 Netbeans在 initializeAnalytics 的第一行和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) {
}
}