0

我有以下代码可以使用 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>

我试过改变一切,现在我不知道该怎么做!

4

1 回答 1

0

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

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

于 2012-09-12T18:21:59.227 回答