簡體   English   中英

使用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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM