java - Spring Boot 中的 Google 日历 API

标签 java spring-mvc spring-boot google-calendar-api google-cloud-platform

我正在尝试在 Spring Boot 中使用 Google Calendar API。 在 application.yml 中我有类似的内容:

security:
  oauth2:
    client:
      clientId: ${g.client.id}
      clientSecret: ${g.client.secret}
      accessTokenUri: https://www.googleapis.com/oauth2/v4/token
      userAuthorizationUri: https://accounts.google.com/o/oauth2/v2/auth
      clientAuthenticationScheme: form
      scope: openid, email, profile, https://www.googleapis.com/auth/calendar
    resource:
      userInfoUri: https://www.googleapis.com/oauth2/v3/userinfo
      preferTokenInfo: true

我已经收到申请

@SpringBootApplication
@EnableOAuth2Sso
public class GoogleAuthenticationApplication extends OAuth2SsoDefaultConfiguration {

身份验证有效并且访问日历范围似乎已被授予。 我现在正在寻找一种使用 token 访问 Google 日历服务的方法 也许用这个?

OAuth2RestTemplate oAuth2RestTemplate

还有一些来自 Google App Engine 的类?

任何帮助将不胜感激。

最佳答案

您可能想先检查一下这个documentation其中指出,您的应用程序可以使用访问 token 来调用 Google API,并且可以通过使用适合您的语言的 Google API 客户端库或使用 HTTP 直接与 OAuth 2.0 系统交互来完成此任务。

有关如何准备进行授权 API 调用的更多信息,请参阅 Using OAuth 2.0 for Server to Server Applications .

除此之外,您可能还想检查此 tutorial其中提供了一些有关如何在 Spring boot 中正确使用访问 token 的指南。

您可能想尝试教程中给出的示例,其中显示了如何使用访问 token 来询问一些个人详细信息,或者来自此 GitHub post .

希望有帮助。

关于java - Spring Boot 中的 Google 日历 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42769550/

相关文章:

spring-boot - 如何使用zuul代理过滤器路由到外部url

java - 以最大概率从名片中提取地址

java - 如何使用hibernate获取记录

java - 基本的 Spring MVC 数据绑定(bind)

java - 如何使用 Spring Boot 修复计划任务问题

Spring 与 JAX-RS

java - 如果使用 WebMvcConfigurationSupport 添加转换器,Swagger OpenAPI 3 不会在 springboot 2 上显示

spring - 如何在 Spring Boot 应用程序中向 STOMP CREATED 消息添加自定义 header ?

java - 我可以在不同项目之间共享 IntelliJ Idea 的设置吗?

java - 生产者消费者请求取消