Java Google日历API:将事件获取为JSON
我已经花了好几个小时看文档了,但我就是想不出来。我只需要访问我自己的日历。那么,我必须采取哪些步骤?身份验证是如何工作的 谢谢,Java Google日历API:将事件获取为JSON,java,google-api,google-calendar-api,Java,Google Api,Google Calendar Api,我已经花了好几个小时看文档了,但我就是想不出来。我只需要访问我自己的日历。那么,我必须采取哪些步骤?身份验证是如何工作的 谢谢, Joe我使用此代码访问日历列表,即返回我创建的日历的详细信息。我希望有帮助。我正在使用OAuth 2.0草案12和Google日历API v3 @RequestMapping(value="/authenticate.do" , method={ RequestMethod.GET , RequestMethod.POST }) public void
Joe我使用此代码访问日历列表,即返回我创建的日历的详细信息。我希望有帮助。我正在使用OAuth 2.0草案12和Google日历API v3
@RequestMapping(value="/authenticate.do" , method={ RequestMethod.GET , RequestMethod.POST })
public void authenticate(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
List <String> scopes = new LinkedList<String>();
scopes.add(scope);
AuthorizationCodeRequestUrl authorize = new GoogleAuthorizationCodeRequestUrl(client_id, redirect_uri, scopes);
authorize.setRedirectUri(redirect_uri);
String authorize_url = authorize.build();
log.info(authorize_url);
response.sendRedirect(authorize_url);
}
还有最后一个音符。我是从一个web应用程序中完成的。希望这有帮助。请参考:我正在使用Java。这是桌面应用程序、web应用程序还是移动应用程序?对于其中的每一个,OAuth 2.0的处理方式都不同。至于使用日历API,我建议您使用自己的解决方案,而不是使用Google的Java客户端库,因为客户端库上的文档几乎不存在。它是一个web应用程序。当我使用REST时,身份验证是如何工作的?我只想访问我自己的日历(私人日历)。我认为您仍然可以使用客户端库进行身份验证,除非这方面的文档太差。我构建了自己的OAuth 2.0解决方案,但它是在VBA中,它也是用于桌面/客户端应用程序的,所以我不确定在这方面我能帮你多少忙。我可以给你粗略的概念/概述,但我认为谷歌的文档已经做到了这一点。
@RequestMapping(value="/importCalendar.do", method={ RequestMethod.GET , RequestMethod.POST })
public void importCalendarList(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
PrintWriter p = response.getWriter();
String code = request.getParameter("code");
HttpTransport transport = new NetHttpTransport();
JsonFactory jsonFactory = new JacksonFactory();
GoogleTokenResponse res = new GoogleAuthorizationCodeTokenRequest(transport, jsonFactory, client_id, client_secret, code, redirect_uri).execute();
String accessToken = res.getAccessToken();
Calendar.Builder builder = new Calendar.Builder(transport, jsonFactory, null);
builder.setCalendarRequestInitializer(new CalendarRequestInitializer(accessToken));
Calendar calendarService = builder.build();
Calendar.CalendarList.List list = calendarService.calendarList().list();
list.setOauthToken(accessToken);
List <CalendarListEntry>list1=list.execute().getItems();
String id = list1.get(0).getId();
p.write(id);
for(CalendarListEntry temp:list1) {
p.println(temp.getSummary());
temp.getId();
}
}
https://google-api-client-libraries.appspot.com/documentation/calendar/v3/java/latest/index.html