有没有人在卷曲中使用TWILIO api并在JSON foRMAT中使用响应?
如何使用twilio api CURL以json格式获取发送sms响应的响应
以下代码正在运行,但响应不是格式化文本。
$AccountSid = "SANDBOX_ACC_ID";
$AuthToken = "SANDBOX_TOKEN";
$url = "https://api.twilio.com/2010-04-01/Accounts/$AccountSid/SMS/Messages";
$from = "+MAGICNUMBER";
$to = "+XXXXXXXXXX"; // twilio trial verified number
$body = "Sending test SMS using Twilio Api";
$data = array (
'From' => $from,
'To' => $to,
'Body' => $body,
);
$post = http_build_query($data);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "$AccountSid:$AuthToken");
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($curl);
curl_close($curl);
//var_dump($post);
echo "<pre>";
echo 'testing with curl '.$response;
echo "</pre>";
答案 0 :(得分:1)
来自Twilio docs:
“Twilio还支持将资源表示作为JSON返回。只需将.json扩展名添加到任何资源URI。”
举个例子,以下是如何获得json格式的消息列表:
GET /2010-04-01/Accounts/AC228b9.../Messages/SM1f0e8ae6ade43cb3c0ce4525424e404f.json