Twilio sending message Using twilio library

跟風遠走 提交于 2020-01-13 16:24:05

问题


Sending twilio message from my api returns this error

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

this is how I send a message. anyone incountered a problem?

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

this is the documentation I followed

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

How do I create Messages.json

I used this https://github.com/twilio/twilio-php on laravel 4.2


回答1:


Hi Twilio developer evangelist here.

Sorry to hear you're having trouble with your code.

You seem to not have posted your complete code, so I don't see where you actually require the library.

I have however written an example which worked for me.

// 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!"
);

I have removed some sensitive data on the code, but if you replace that with your token and numbers, you should be able to send a text message correctly.

Also, just in case you have the contents of the 'Services' folder elsewhere, make sure your paths are correct.




回答2:


Another Twilio developer evangelist here. Think I might be able to help.

The error message you got was this:

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

The key point is the URL, particularly the double slash in the middle. That is where your Account Sid should be, thus leading to the 404 error.

In this case, I would double check how you are setting $sid. Make sure it is assigned before you try to create the Twilio client object.




回答3:


You have entered messages when it should be sms_messages.

CHANGE

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

INTO

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

Also make sure that you are running this code inside a class otherwise you need to remove the $this-> from your code and use a local varible.



来源:https://stackoverflow.com/questions/32931338/twilio-sending-message-using-twilio-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!