Rails,存储Google Client API的JSON凭据以及如何访问它的位置?
在我的Google Developer Console中,我已下载了凭据json文件。 它看起来像这样:
client_secret-000000000-aaaaaaaaaa0a.apps.googleusercontent.json
我想使用google-api-client
获取ruby。 我需要在什么文件夹中放置这个json
文件? 另外,我该如何访问它? 所有关于此的教程都会跳过它。
您可以将它存储在任何合适的目录中,例如config
(传统), lib
, db
等。
要访问它,请使用:
client = Google::APIClient.new( application_name: 'Your Google API Application', application_version: YOUR_VERSION ) client.authorization = Google::APIClient::ClientSecrets.load( File.join( Rails.root, 'config', 'client_secret-000000000-aaaaaaaaaa0a.apps.googleusercontent.json' ) ).to_authorization