如何将Google登录凭据设置为环境变量(或“将其传递给方法”)?

时间:2023-01-24 10:56:23

The documentation for the roo library says that in order to use Google spreadsheets I need to

roo库的文档说我需要使用Google电子表格

set the environment variables ‘GOOGLE_MAIL’ and ‘GOOGLE_PASSWORD’ or you pass the Google-name and -password to the Google#new method.

设置环境变量“GOOGLE_MAIL”和“GOOGLE_PASSWORD”,或者将Google名称和-password传递给Google#new方法。

I'm new to Ruby, naively just tried to change the environment variable (on Windows) by doing this in the system properties, but it seems that it's not environment variables in this sense (and I guess that'd be a bad way to store sensitive data anyway)

我是Ruby新手,天真地试图通过在系统属性中执行此操作来更改环境变量(在Windows上),但在这种意义上它似乎不是环境变量(我猜这是一个糟糕的方式无论如何存储敏感数据)

I've deleted the environment variables from my (user not system) settings again, so back to square one. How do I follow this instruction? I don't understand what it means by "pass the Google-name and Google-password to the Google#new method", I'm trying to run the line

我已经从我的(用户非系统)设置中删除了环境变量,所以回到原点。我该如何遵循这条指令?我不明白“将谷歌名称和谷歌密码传递给谷歌#新方法”意味着什么,我正试图运行该行

oo = Roo::Google.new('"'+sheetfull'"')

and I could ask for the details in the program rather than changing system settings (to make it easier for other people to use my code) with something along these lines

我可以在程序中询问详细信息,而不是更改系统设置(以便其他人更容易使用我的代码)

puts "What's your email?"
GOOGLE_MAIL = gets
puts "What's your password?"
GOOGLE_PASSWORD = gets

so that these 'environment variables' are set up before the spreadsheet is called with oo, or else it results in an error.

以便在使用oo调用电子表格之前设置这些“环境变量”,否则会导致错误。

I'm not quite sure how I'd tell it that they've been given though... I tried the code above but it's obviously initialising GOOGLE_MAIL and GOOGLE_PASSWORD as constants(?) that don't get "passed to any methods"

我不太确定我是怎么告诉他们他们已经被给出了...我尝试了上面的代码,但显然将GOOGLE_MAIL和GOOGLE_PASSWORD初始化为常量(?),不会“传递给任何方法”

Sorry if I've worded this poorly, I'm still learning all the lingo! Feel free to call me out on any of the things I've named etc. etc.

对不起,如果我措辞不好,我还在学习所有的术语!请随时给我打电话,告诉我任何我命名的事情等等。

1 个解决方案

#1


1  

You can set environment variables using the instructions here: https://superuser.com/questions/284342/what-are-path-and-other-environment-variables-and-how-can-i-set-or-use-them

您可以使用以下说明设置环境变量:https://superuser.com/questions/284342/what-are-path-and-other-environment-variables-and-how-can-i-set-or-use-他们

Alternatively, you can pass the values you prepared to roo like so:

或者,您可以将准备好的值传递给roo,如下所示:

Roo::Google.new(sheetfull, user: GOOGLE_MAIL, password: GOOGLE_PASSWORD)

#1


1  

You can set environment variables using the instructions here: https://superuser.com/questions/284342/what-are-path-and-other-environment-variables-and-how-can-i-set-or-use-them

您可以使用以下说明设置环境变量:https://superuser.com/questions/284342/what-are-path-and-other-environment-variables-and-how-can-i-set-or-use-他们

Alternatively, you can pass the values you prepared to roo like so:

或者,您可以将准备好的值传递给roo,如下所示:

Roo::Google.new(sheetfull, user: GOOGLE_MAIL, password: GOOGLE_PASSWORD)