错误的身份验证错误Rails连接到Google驱动器 [英] Bad Authentication Error Rails connecting to google drive

查看:160
本文介绍了错误的身份验证错误Rails连接到Google驱动器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通讯录控制器,该控制器具有一种方法,可以将表单提交的数据连接并保存到我在Google驱动器上的帐户中的电子表格中(app/models/contact.rb):

I have a contacts controller which has a method to connect and save the data submitted from the form to a spreadsheet in my account on 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中:

The method calls on environment variables I set up with figaro which are saved config/environments/development.rb as follows:

GMAIL_USERNAME: tgolsby@gmail.com
GMAIL_PASSWORD: Paxxword (obviously this is a place holder for my actual password in the .yml file)

提交表单时,出现以下错误:

When I submit my form I get the following error:

*GoogleDrive::AuthenticationError at /contacts
Authentication failed for tgolsby: Response code 403 for post https://www.google.com/accounts/ClientLogin: Error=BadAuthentication*

它指向联系人模型中的以下行:

It points to the following line in the contacts model:

*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文件中是正确的.我已经完成了本教程并重复了所有步骤,但是我无法弄清为什么该应用无法连接到Google.我还检查了自己的Google帐户是否没有设置两步验证.

I have checked and rechecked my username and password and am 100% sure they are correct in the application.yml file. I have gone through the tutorial and repeated all the steps but I just cant' figure out why the app is having trouble connecting to google. I have also checked that I don't have 2 step verification set up on my google account.

推荐答案

您可能遇到与我相同的问题.我使用google_drive gem访问了我的Google文档,该项目是我一年没有接触过的.我曾经能够通过使用session = GoogleDrive.login('rosalyntest1@gmail.com', 'password')启用会话来访问我的Google文档,但现在却遇到了与您相同的错误.

You might have the same issue I had. I was accessing my google doc using the google_drive gem on a personal project I had not touched in over a year. I used to be able to access my google doc by enabling a session using session = GoogleDrive.login('rosalyntest1@gmail.com', 'password') but was now getting the same error as you.

我使用密码登录了该帐户,并看到了一封来自Google的电子邮件,主题为登录被阻止".我点击了链接 https://www.google.com/settings/security/lesssecureapps 以仅对该帐户启用不太安全的应用访问权限,并能够使用相同的代码在本地启用会话.我会检查您的Google帐户,看看您是否收到电子邮件或启用安全性较低的应用访问权限,然后重试.

I logged into that account using my password and saw an email from google with a subject of "sign in blocked." I followed the link https://www.google.com/settings/security/lesssecureapps to enable less secure app access for that account only and was able to enable a session locally using the same code. I would check your google account and see if you received an email or enable less secure app access and try again.

这篇关于错误的身份验证错误Rails连接到Google驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆