私の連絡先コントローラー (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 (バージョン 2.1.6) による Learn on Rails を正確にフォローしてきましたが、何が問題なのかわかりませんでした。また、私は Google の 2 段階認証プロセスを使用しておらず、安全性の低いアプリを許可しています。構成ファイルを変更した後、Web サーバーを再起動しようとしましたが、まだ結果はありません。