访问GoogleCredentials时出错



我有以下代码来使用OAUTH 2.0访问日历API。

public static Calendar build(String accessToken) {
    HttpTransport transport = AndroidHttp.newCompatibleTransport();
    JacksonFactory jsonFactory = new JacksonFactory();
    httpRequestInitializer(credential);
    Log.i("Reached calendar builder", "Reached calendar builder");
    GoogleCredential credential = new GoogleCredential();

    Calendar service = new Calendar.Builder(transport, jsonFactory, credential)
            .setApplicationName("Meetrbus/1.0")
            .setHttpRequestInitializer(credential);
            .setJsonHttpRequestInitializer(
                    new JsonHttpRequestInitializer() {
                        public void initialize(JsonHttpRequest request) {
                            CalendarRequest calendarRequest = (CalendarRequest) request;
                            // TODO: Get an API key from Google's APIs
                            // Console:
                            // https://code.google.com/apis/console.
                            calendarRequest
                                    .setKey("API_ACCESS_KEY");
                        }
                    }).build();


    return service;
}

当我运行代码时,应用程序强制关闭,logcat给我以下错误:

Could not find class 'com.google.api.client.util.Clock', referenced from method com.google.api.client.auth.oauth2.Credential.<init>

我试着改变一切,但现在我不知道该怎么办!

您需要在类路径中包含google-http-java客户端jar。

最新的谷歌http java客户端可以从这里获得:http://code.google.com/p/google-http-java-client/downloads/list

相关内容

  • 没有找到相关文章

最新更新