我有以下代码可以使用 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>
我试过改变一切,现在我不知道该怎么做!