Rails, where to store JSON credentials of Google Client API and how to access it?

送分小仙女□ 提交于 2019-12-24 18:01:15

问题


In my Google Developer Console, I have downloaded credentials json file. It looks like this:

client_secret-000000000-aaaaaaaaaa0a.apps.googleusercontent.json

I want to use google-api-client for ruby. In what folder do I need to place this json file? Also, how can I access it? All tutorials about this just skips it.


回答1:


You may store it in any suitable directory, e. g. config (conventionally), lib, db etc.

To access it, use:

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


来源:https://stackoverflow.com/questions/34372312/rails-where-to-store-json-credentials-of-google-client-api-and-how-to-access-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!