我正在尝试在 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/