我想爲我的應用授權Calendar API。我無法獲得使用提供的.json文件或使用ENV變量的授權。如何爲具有ENV變量的服務帳戶授權Google API客戶端?
有人可以請向我解釋如何做到這一點?我寧願使用ENV變量,但如果這是不可能的,那麼任何有效的方法將是驚人的!
這是我現在有:
client = Google::APIClient.new(:application_name => 'App Name', :application_version => '1.0.0')
client_secrets = Google::APIClient::ClientSecrets.load
client.authorization = Signet::OAuth2::Client.new(
:token_credential_uri => 'https://accounts.google.com/o/oauth2/token',
:audience => 'https://accounts.google.com/o/oauth2/token',
:scope => 'https://www.googleapis.com/auth/calendar',
:issuer => Rails.application.secrets.GOOGLE_CLIENT_EMAIL,
:person => Rails.application.secrets.GOOGLE_CALENDAR_EMAIL
)
client.authorization.fetch_access_token!
service = client.discovered_api('calendar', 'v3')
你應該在你的問題的評論中包括你提到的錯誤,這將有助於找到問題。 –