ruby-on-rails – 错误的身份验证错误Rails连接到谷歌驱动器
发布时间:2020-12-17 02:40:04 所属栏目:百科 来源:网络整理
导读:我有一个联系人控制器,它有一种方法可以将表单中提交的数据连接并保存到我在google drive(app / models / contact.rb)帐户中的电子表格中: def update_spreadsheet connection = GoogleDrive.login(ENV["GMAIL_USERNAME"],ENV["GMAIL_PASSWORD"]) ss = conn
我有一个联系人控制器,它有一种方法可以将表单中提交的数据连接并保存到我在google drive(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 该方法调用我用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) 当我提交表单时,我收到以下错误: *GoogleDrive::AuthenticationError at /contacts Authentication failed for tgolsby: Response code 403 for post https://www.google.com/accounts/ClientLogin: Error=BadAuthentication* 它指向联系人模型中的以下行: *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* 我检查并重新检查了我的用户名和密码,并且100%确定它们在application.yml文件中是正确的.我已经完成了教程并重复了所有步骤,但我无法弄清楚为什么应用程序无法连接到谷歌.我还检查过我的谷歌帐户没有设置2步验证. 解决方法
你可能遇到了同样的问题.我使用google_drive gem访问我的谷歌文档,这个项目是我一年没有碰过的.我曾经能够通过使用session = GoogleDrive.login(‘rosalyntest1 @ gmail.com’,’password’)启用会话来访问我的Google文档,但现在得到了与您相同的错误.
我使用密码登录了该帐户,并看到了谷歌发送的一封电子邮件,主题是“登录已被屏蔽”.我按照链接https://www.google.com/settings/security/lesssecureapps仅为该帐户启用了不太安全的应用程序访问,并且能够使用相同的代码在本地启用会话.我会检查您的Google帐户,看看您是否收到了电子邮件或启用了不太安全的应用访问权限,然后重试. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |