0

我在 twilio 上创建了免费帐户,我得到了这个生成的电话号码

+1 (201) 345-7453

当我尝试在代码中使用这个电话时

$sms = $client->account->sms_messages->create("+1 (201) 345-7453", "myphone # here", "Jenny please?! I love you <3", array());
echo $sms->sid;

Fatal error: Uncaught exception 'Services_Twilio_RestException' with message 'The From phone number +12013457453 is not a valid, SMS-capable inbound phone number or short code for your account

4

1 回答 1

2

当您调用 create() 方法时,“From”属性变为“from”,因为

abstract class Services_Twilio_InstanceResource extends Services_Twilio_Resource {
    ...
    $decamelizedParams = $this->client->createData($this->uri, $params);
    $this->updateAttributes($decamelizedParams);

https://github.com/twilio/twilio-php/blob/master/Services/Twilio/InstanceResource.php#L31

Twilio 已弃用“SMS 消息”资源,因此不要指望修复。我建议您转到现在的“消息”资源(https://twilio-php.readthedocs.org/en/latest/usage/rest/messages.html#sending-a-message)。

这很容易...

$response = $client->account->messages->create([
    'To'       => '+10000000000',
    'From'     => '+10000000000',
    'Body'     => $msg,
    'MediaUrl' => 'https://some.com/image.jpg'
]);

echo $response;
于 2015-10-17T05:02:28.793 回答