2014-09-12 45 views
0

我是一名新手,試圖將Google Calendar API實現到基於Web的應用程序中,並按照它們提供給t的說明進行操作後,獲取信息僅工作約20分鐘(而訪問令牌仍然有效)。我知道你需要刷新令牌才能生成新的訪問令牌,但從終端運行此腳本(Google在其文檔中提供)不提供刷新令牌。如何在使用Google Calendar API Ruby庫時獲取刷新標記?

我在終端執行的代碼: google-api oauth-2-login --scope=https://www.googleapis.com/auth/calendar --client- id=CLIENT_ID --client-secret=CLIENT_SECRET

這產生了所有我的鑰匙,其中A .yaml文件看起來像這樣:

--- 
mechanism: oauth_2 
scope: SCOPE_HERE 
client_id: CLIENT_ID_HERE 
client_secret: CLIENT_SECRET_HERE 
access_token: ACCESS_TOKEN_HERE 
refresh_token: 

,他們如果訪問令牌提供的代碼到期:

oauth_yaml = YAML.load_file('.google-api.yaml') 
client = Google::APIClient.new 
client.authorization.client_id = oauth_yaml["client_id"] 
client.authorization.client_secret = oauth_yaml["client_secret"] 
client.authorization.scope = oauth_yaml["scope"] 
client.authorization.refresh_token = oauth_yaml["refresh_token"] 
client.authorization.access_token = oauth_yaml["access_token"] 

if client.authorization.refresh_token && client.authorization.expired? 
    client.authorization.fetch_access_token! 
end 

service = client.discovered_api('calendar', 'v3') 

因此,根據YAML文件,client.authorization.refresh_token始終是 '零',它從來沒有得到一個NE訪問令牌。另外,client.authorization.expired?始終返回false,即使應用程序停止工作。 我在這裏看到了一些關於同一問題的其他問題,但是由於我通過終端命令生成了我的令牌,所以我不確定如何去獲取該令牌。

回答

相關問題