Bad Authentication Error Rails connecting to google drive

前端 未结 3 1848
被撕碎了的回忆
被撕碎了的回忆 2021-01-19 04:20

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):<

相关标签:
3条回答
  • 2021-01-19 04:43

    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.

    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.

    0 讨论(0)
  • 2021-01-19 04:49

    The code is good (you can check it against the learn-rails example application). It looks exactly like the code from the Learn Ruby on Rails book.

    That means the problem is a result of an environment or configuration issue.

    First, are you running locally, or do you have the problems after deploying to Heroku?

    If running locally, here are things you can try to troubleshoot:

    1) Try restarting the web server. When you change configuration files, the server has to be restarted.

    2) Replace ENV["..."] in the code and use the credentials directly ("hardcode the credentials"). Be careful not to check the code into the git repo with the hardcoded credentials (and don't push to GitHub because you would expose your credentials).

    3) Can you send email from the application? Comment out the code that updates the spreadsheet and you should be able to send email if your credentials are correct.

    0 讨论(0)
  • 2021-01-19 04:54

    I had this problem as well, and I was able to fix it by making the ENV["GMAIL_PASSWORD"] code in my contacts model all caps just as it is in my environment. It was not working when I only had the first letter caps in the code but everything in caps in the env variable, so be sure to consider the case sensitivity of your environments.

    0 讨论(0)
提交回复
热议问题