4

我正在按照 Google 的分步配置说明进行操作,但由于某种原因,我找不到他们要求我导入的一些包。我的应用程序无法找到的软件包是(或我的 IDE 抱怨的行):

import com.google.api.client.auth.oauth2.draft10.AccessTokenResponse;
import com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAccessProtectedResource;
import com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAccessTokenRequest.GoogleAuthorizationCodeGrant;
import com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAuthorizationRequestUrl;

我似乎找不到装这些的罐子。我的类路径包含:

//The Google Calendar Client API:
google-api-services-calendar-v3-rev16-1.8.0-beta.jar

//And of course the Google API Core:
commons-logging-1.1.1.jar
google-api-client-1.11.0-beta.jar
google-api-client-1.11.0-beta.jar.properties
google-api-client-android-1.11.0-beta.jar
google-api-client-android-1.11.0-beta.jar.properties
google-api-client-android2-1.11.0-beta.jar
google-api-client-android2-1.11.0-beta.jar.properties
google-api-client-appengine-1.11.0-beta.jar
google-api-client-java6-1.11.0-beta.jar
google-http-client-1.11.0-beta.jar
google-http-client-1.11.0-beta.jar.properties
google-http-client-android-1.11.0-beta.jar
google-http-client-android-1.11.0-beta.jar.properties
google-http-client-android2-1.11.0-beta.jar
google-http-client-android2-1.11.0-beta.jar.properties
google-http-client-android3-1.11.0-beta.jar
google-http-client-android3-1.11.0-beta.jar.properties
google-http-client-appengine-1.11.0-beta.jar
google-http-client-gson-1.11.0-beta.jar
google-http-client-gson-1.11.0-beta.jar.properties
google-http-client-jackson-1.11.0-beta.jar
google-http-client-jackson-1.11.0-beta.jar.properties
google-http-client-jackson2-1.11.0-beta.jar
google-http-client-jackson2-1.11.0-beta.jar.properties
google-oauth-client-1.11.0-beta.jar
google-oauth-client-1.11.0-beta.jar.properties
google-oauth-client-appengine-1.11.0-beta.jar
google-oauth-client-java6-1.11.0-beta.jar
google-oauth-client-jetty-1.11.0-beta.jar
google-oauth-client-servlet-1.11.0-beta.jar
gson-2.1.jar
gson-2.1.jar.properties
guava-11.0.1.jar
guava-11.0.1.jar.properties
httpclient-4.0.3.jar
httpcore-4.0.1.jar
jackson-core-2.0.5.jar
jackson-core-2.0.5.jar.properties
jackson-core-asl-1.9.9.jar
jackson-core-asl-1.9.9.jar.properties
jdo2-api-2.3-eb.jar
jetty-6.1.26.jar
jetty-util-6.1.26.jar
jsr305-1.3.9.jar
transaction-api-1.1.jar
xpp3-1.1.4c.jar

我不确定我缺少什么,但我需要这些库来继续本教程。如果需要更多信息,我很乐意提供。我是 Google Calendar API 的新手。任何帮助表示赞赏!谢谢!

4

1 回答 1

12

遗憾的是,截至目前,Google 尚未更新Java 配置源代码。您不需要这些类,正如其他人在评论中指出的那样,它们已被弃用。

将“draft10”进口替换为:

import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.auth.oauth2.GoogleTokenResponse;
import com.google.api.services.calendar.CalendarScopes;

然后,将授权代码(从注释“Step 1: Authorize -->”开始)替换为:

GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
                httpTransport, jsonFactory, clientId, clientSecret,
            Arrays.asList(CalendarScopes.CALENDAR)).setAccessType("online")
                .setApprovalPrompt("auto").build();

String url = flow.newAuthorizationUrl().setRedirectUri(redirectUrl).build();
System.out.println("Please open the following URL in your browser then type the authorization code:");

System.out.println("  " + url);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String code = br.readLine();

GoogleTokenResponse response = flow.newTokenRequest(code)
                .setRedirectUri(redirectUrl).execute();
GoogleCredential credential = new GoogleCredential()
                .setFromTokenResponse(response);

// Create a new authorized API client
Calendar service = new Calendar.Builder(httpTransport, jsonFactory,
                credential).build();

我遇到了同样的问题,发现驱动器示例代码是最新的。我猜到了我的方式,并使它工作。此处描述了“授权代码流程” 。

于 2012-12-17T09:54:12.297 回答