java - 带有服务帐户的 Google Calendar 1.17 API - 未解析的 GoogleClient 类

标签 java eclipse api google-calendar-api

我正在尝试使用 1.17-rc Google Calendar Java API 创建一个简单的示例案例。

HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory jsonFactory =JacksonFactory.getDefaultInstance()
String email = "test@domain.com";

java.io.File licenseFile = new java.io.File("C:/Dev/apache-tomcat-6.0.37/app/webapps/12334b4c229abc2f7da1c3a9100d5d15c11d9874-privatekey.p12");

GoogleCredential credential = new GoogleCredential.Builder()
    .setTransport(httpTransport)
    .setJsonFactory(jsonFactory)
    .setServiceAccountId("51235964123-k2vr57p9jh0r3i5cj95frvh2qwe35ofg@developer.gserviceaccount.com") 
    .setServiceAccountUser(email)
    .setServiceAccountScopes(new ArrayList<String>(){{add(CalendarScopes.CALENDAR);}})
    .setServiceAccountPrivateKeyFromP12File(licenseFile)
    .build();

    com.google.api.services.calendar.Calendar client = 
        new com.google.api.services.calendar.Calendar.Builder(
        httpTransport, jsonFactory, credential)
                .setApplicationName("Google Calendar Sync").build();

    Calendar calendar = client.calendars().get(email).execute();

我什至没有运行这个 - 它给我一个提示(在 Eclipse 中)“类型 com.google.api.client.googleapis.services.GoogleClient$Builder 无法解析。它是间接的从所需的 .class 文件中引用”。我已经安装了整个 Google Calender API 依赖项 ZIP 并将所有包含的 JAR 文件添加到我的类路径中。但它确实看起来像那个类不在其中任何一个 - 我在 google-api-client-1.17.0-rc.jar 中看到一个 com.google.api.client.googleapis.services.AbstractGoogleClient,但没有 com .google.api.client.googleapis.services.GoogleClient 在任何提供的 JAR 中。

我在两个不同的场合对此进行了非常广泛的谷歌搜索,但我找不到其他人有这个问题,所以我想我一定是在做一些我看不到的真正愚蠢的事情 - 如果有人能告诉我什么,我将不胜感激...

最佳答案

我也有这个问题,最后我发现1.7以后的google-api-client版本有GoogleClient类。

您可以在此处下载 jar 文件。 http://grepcode.com/snapshot/repo1.maven.org/maven2/com.google.api-client/google-api-client/1.7.0-beta/

这是一个迟到的答案,但希望这会对某人有所帮助。

关于java - 带有服务帐户的 Google Calendar 1.17 API - 未解析的 GoogleClient 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20460822/

相关文章:

java - 循环遍历列表 - 当索引到达末尾时,从 0 开始

Javadoc 不匹配代码

java - 关于 Android 和 Java 开发中良好实践的问题

eclipse - Mac eclipse 将工作区设置为 dropxbox 导致启动崩溃

php - 使用 PHP 生成 Javascript 文件

java - Android 蓝牙 ScanFilter 部分字符串匹配

Eclipse cucumber 插件

eclipse - 在 eclipse 中的 tomcat 上运行 GWT

c# - SSIS Web API 连接

C++ Win32,编辑控件可以是所有者绘制的吗?