如何修复"Twilio::REST::RestError"?



我按照这里的文档进行操作: 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):

我的消息控制器代码为:

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

很难说给出的详细程度,但通常您的secrets.yml文件中存在错误。仔细检查我们的 Twilio 密钥设置是否正确。

造成这种情况的原因之一可能是您的机密环境没有接收到环境中的更改。跑:

source ~/.bashrc

刷新环境设置。之后(这很可能是此问题的原因(,运行以下命令以停止spring以便下次重新进行更改:

bin/spring stop

最新更新