身份验证失败:发布的响应代码403 - 错误= BadAuthentication

时间:2015-03-18 22:13:12

标签: ruby-on-rails learn-ruby-on-rails

在我的联系人控制器(app / model / contact.rb)中,将数据连接并保存到我的google驱动器上的电子表格似乎是正确的方法,我尝试在本地运行它,我一直收到错误消息但没有收到任何电子邮件。

我在我的Gemfile中安装了gem google_drive:gem'google_drive'

require 'google_drive_v0'
class Contact
  include ActiveModel::Model
  attr_accessor :name, :string
  attr_accessor :email, :string
  attr_accessor :content, :string

  validates_presence_of :name
  validates_presence_of :email
  validates_presence_of :content
  validates_format_of :email, with: /\A[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}\z/i
  validates_length_of :content, :maximum => 500

    def update_spreadsheet
    connection = GoogleDriveV0.login(Rails.application.secrets.email_provider_username, Rails.application.secrets.email_provider_password
)
    ss = connection.spreadsheet_by_title('Learn-Rails-Example')
    if ss.nil?
      ss = connection.create_spreadsheet('Learn-Rails-Example')
    end
    ws = ss.worksheets[0]
    last_row = 1 + ws.num_rows
    ws[last_row, 1] = Time.new
    ws[last_row, 2] = self.name
    ws[last_row, 3] = self.email
    ws[last_row, 4] = self.content
    ws.save
  end

end

secrets.yml

    development:
      email_provider_username: <%= ENV["GMAIL_USERNAME"] %>
      email_provider_password: <%= ENV["GMAIL_PASSWORD"] %>

      mailchimp_api_key: <%= ENV["MAILCHIMP_API_KEY"] %>
      mailchimp_list_id: <%= ENV["MAILCHIMP_LIST_ID"] %>
      owner_email: <%= ENV["OWNER_EMAIL"] %>
      secret_key_base: [remove long strings]    

   test:
      secret_key_base: [remove long strings]

    production:
      email_provider_username: <%= ENV["GMAIL_USERNAME"] %>
      email_provider_password: <%= ENV["GMAIL_PASSWORD"] %>
      mailchimp_api_key: <%= ENV["MAILCHIMP_API_KEY"] %>
      mailchimp_list_id: <%= ENV["MAILCHIMP_LIST_ID"] %>
      owner_email: <%= ENV["OWNER_EMAIL"] %>
      secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>  

.bashrc或.bash_profile

export SECRET_KEY_BASE= [remove long strings]
export GMAIL_USERNAME="[remove]"
export GMAIL_PASSWORD="[remove]"
export OWNER_EMAIL="[remove]"

错误讯息:

GoogleDriveV0::AuthenticationError at /contacts

Authentication failed for : Response code 403 for post https://www.google.com/accounts/ClientLogin: Error=BadAuthentication

我一直关注Daniel Kehoe的学习Rails(版本2.1.6),无法弄清楚出了什么问题。同时检查,我不使用谷歌的两步验证,并允许不太安全的应用程序。我尝试在更改配置文件后重新启动Web服务器,仍然没有结果。

0 个答案:

没有答案