使用 scala 访问 google API,前端 Ruby on Rails

Using scala to access google API, front end in Ruby on Rails

所以我的主要应用程序是用 Ruby/Rails 编写的,这是初步的 oauth2 操作发生的地方。目前我存储来自初始交互的电子邮件和刷新令牌,现在我想使用 Scala 脚本使用用户凭据在后台从 api 检索数据。 (点一个API没有..?)

在遵循 google java api 客户端示例页面中的许多示例后:https://github.com/google/google-api-java-client-samples,我发现他们要我通过打开重新验证用户一个新的选项卡并实际登录。因为我已经对他们进行了身份验证,有没有一种方法可以让我简单地连续检索数据而不需要他们再次登录,因为这个脚本应该在后台 运行 ?

要使用 java-api-client 库刷新访问令牌:

import com.google.api.client.googleapis.auth.oauth2.GoogleCredential

val credential = new GoogleCredential.Builder()
.setTransport(transport)
.setJsonFactory(jsonFactory)
.setClientSecrets(CLIENT_ID, CLIENT_SECRET)
.build()

credential.setRefreshToken(refreshToken) // get token from DB or wherever you have persisted it
credential.refreshToken()
credential.getAccessToken // returns new, refreshed access token