Twilio发送消息使用Twilio库


Twilio sending message Using twilio library

从我的api发送twilio消息返回此错误

Twilio sending message The requested resource/2010-04-01/Accounts//Messages。未找到Json

这是我发送消息的方式。有人遇到问题了吗?

$this->client = new 'Services_Twilio($sid, $token);
     return $this->client->account->messages->sendMessage($from ,$to, $message);

这是我所遵循的文档

https://www.twilio.com/docs/api/rest/sending-sms

如何创建Messages.json

我使用这个https://github.com/twilio/twilio-php在laravel 4.2

这里是另一位Twilio开发者布道者。我想我也许能帮上忙。

你得到的错误信息是:

The requested resource /2010-04-01/Accounts//Messages.json was not found

关键是URL,特别是中间的双斜杠。这就是你的Account Sid应该在的位置,因此导致404错误。

在这种情况下,我会仔细检查如何设置$sid。在尝试创建Twilio客户端对象之前,请确保分配了它。

大家好,这里是Twilio开发者布道者。

很抱歉听到你的代码有问题。

你似乎没有发布你的完整代码,所以我不知道你实际上需要的库。

我已经写了一个适合我的例子。

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = 'AC'; 
$token = '01'; 
$client = new 'Services_Twilio($sid, $token);
$message = $client->account->messages->sendMessage(
    '+44', // From a valid Twilio number
    '+44', // Text this number
    "Hello monkey!"
);

我已经删除了代码上的一些敏感数据,但是如果你用你的令牌和数字替换它,你应该能够正确地发送短信。

另外,为了防止"Services"文件夹的内容在其他地方,请确保你的路径是正确的。

您输入了应该是sms_messages的消息

改变
$this->client->account->messages->sendMessage($from ,$to, $message);

$this->client->account->sms_messages->create($from ,$to, $message);

还要确保在类中运行此代码,否则您需要从代码中删除$this->并使用局部变量