Rails,在哪里存储Google客户端API的JSON凭据以及如何访问它? [英] Rails, where to store JSON credentials of Google Client API and how to access it?
本文介绍了Rails,在哪里存储Google客户端API的JSON凭据以及如何访问它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的Google开发者控制台中,我已下载凭据json文件。它看起来像这样:
client_secret-000000000-aaaaaaaaaa0a.apps.googleusercontent.json
我想为ruby使用 google-api-client
。我需要在哪个文件夹中放置 json
文件?另外,我如何访问它?所有关于此的教程都会跳过它。
解决方案
您可以将其存储在任何合适的目录中, G。 config
(通常), lib
, db
/ p>
要访问它,请使用:
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
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.
解决方案
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
这篇关于Rails,在哪里存储Google客户端API的JSON凭据以及如何访问它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文