我有一个联系人控制器,它有一种方法可以将表单提交的数据连接并保存到我在谷歌驱动器(app/models/contact.rb)上的帐户中的电子表格中:
def update_spreadsheet
connection = GoogleDrive.login(ENV["GMAIL_USERNAME"], ENV["GMAIL_PASSWORD"])
ss = connection.spreadsheet_by_title('Learn-Rails02-Example')
if ss.nil?
ss = connection.create_spreadsheet('Learn-Rails02-Example')
end
Run Code Online (Sandbox Code Playgroud)
该方法调用我用 figaro 设置的环境变量,这些变量保存在 config/environments/development.rb 中,如下所示:
GMAIL_USERNAME: tgolsby@gmail.com
GMAIL_PASSWORD: Paxxword (obviously this is a place holder for my actual password in the .yml file)
Run Code Online (Sandbox Code Playgroud)
当我提交表单时,出现以下错误:
*GoogleDrive::AuthenticationError at /contacts
Authentication failed for tgolsby: Response code 403 for post https://www.google.com/accounts/ClientLogin: Error=BadAuthentication*
Run Code Online (Sandbox Code Playgroud)
它指向联系人模型中的以下行:
*def update_spreadsheet*
**connection = GoogleDrive.login(ENV["GMAIL_USERNAME"], ENV["GMAIL_PASSWORD"])**
*ss = connection.spreadsheet_by_title('Learn-Rails02-Example')
if ss.nil?
ss = connection.create_spreadsheet('Learn-Rails02-Example')
end*
Run Code Online (Sandbox Code Playgroud)
我已经检查并重新检查了我的用户名和密码,并且 100% 确定它们在 application.yml 文件中是正确的。我已经完成了教程并重复了所有步骤,但我无法弄清楚为什么该应用程序无法连接到谷歌。我还检查过我的谷歌帐户没有设置两步验证。