gpt4 book ai didi

java - 如何设置谷歌日历 Java 应用程序

转载 作者:搜寻专家 更新时间:2023-11-01 01:17:46 24 4
gpt4 key购买 nike

我正在逐步执行 configuration instructions由谷歌,但出于某种原因我找不到他们要求我导入的一些包。我的应用无法找到的包是(或我的 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;

我好像找不到装这些的 jar 。我的类路径包含:

//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 的新手。任何帮助表示赞赏!谢谢!

最佳答案

很遗憾,截至目前,谷歌还没有更新the Java configuration source code .您不需要这些类,正如其他人在评论中指出的那样,它们已被弃用。

将“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;

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

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();

我遇到了同样的问题,找到了the drive sample code是最新的。我猜到了我的方法,并成功了。 “授权码流”描述 here .

关于java - 如何设置谷歌日历 Java 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12555117/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com