cod*_*fun 1 ruby-on-rails twilio
我遵循了这里的文档:https : //www.twilio.com/blog/2016/04/receive-and-reply-to-sms-in-rails.html
现在我有以下错误:
Twilio::REST::RestError (Unable to create record: The requested resource /2010-04-01/Accounts//Messages.json was not found):
Run Code Online (Sandbox Code Playgroud)
我的消息控制器代码是:
class MessagesController < ApplicationController
skip_before_action :verify_authenticity_token
# skip_before_action :authenticate_user!, :only => "reply"
def reply
message_body = params["Body"]
from_number = params["From"]
init_twilio
msg = @client.messages.create(
from: Rails.application.secrets.twilio_number,
to: from_number,
body: "Hello! Your number is #{from_number}. This is a xxx
Test Message."
)
end
private
def init_twilio
account_sid = Rails.application.secrets.twilio_sid
auth_token = Rails.application.secrets.twilio_auth_key
@client = Twilio::REST::Client.new account_sid, auth_token
end
end
Run Code Online (Sandbox Code Playgroud)
小智 5
很难说给出的详细程度,但通常您的 secrets.yml 文件中存在错误。仔细检查我们的 Twilio 密钥是否设置正确。