我試圖通過Google API獲取offline access
。我必須從Google日曆中提取數據,而不必每次都登錄用戶。如何使用Google API下線訪問
我已經添加到了我的Gemfile:
gem 'google-api-client', '~> 0.9'
...,並將此向我的控制器:
require 'google/api_client/client_secrets'
class Api::V1::CalendarAccountsController < Api::V1::BaseController
...
在我的行動:
client_secrets = Google::APIClient::ClientSecrets.load(
File.join(
Rails.root,
'config',
'client_secrets.json')
)
@auth_client = client_secrets.to_authorization
@auth_client.update!(
:scope => 'https://www.googleapis.com/auth/calendar.readonly',
:redirect_uri => '/{callback URL}',
:additional_parameters => {
"access_type" => "offline",
"include_granted_scopes" => "true"
}
)
redirect_to @auth_client.authorization_uri.to_s
問題是 - 即使我指定「acces s_type「 as 」offline「,I still不會被要求在Google權限列表(我附上下面的屏幕)中提供離線訪問權限。
而這裏的是,當我叫@auth_client.authorization_uri.to_s
我缺少的東西得到了生成的網址是什麼?
感謝@Mr .Rebot - 我已經添加了'access_type'參數,但我仍然沒有在Google的登錄權限頁面上獲得離線訪問提示(它只是要求對日曆進行只讀訪問),並且我在響應中也沒有得到'refresh_token'。 – Qasim