2014-07-22 84 views
0

有沒有人在JSON foRMAT中使用TWILIO api進行響應?如何獲得以json格式發送短信響應twilio

如何使用twilio API捲曲

這裏是一個工作,但反應未格式化的文本代碼來獲取發送短信響應JSON格式的響應。

$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>"; 

回答

1

Twilio docs

「Twilio也支持返回的資源表示爲JSON只需將上傳.json擴展添加到任何資源URI」

舉個例子,這裏是你將如何獲得消息的列表JSON格式:

GET /2010-04-01/Accounts/AC228b9.../Messages/SM1f0e8ae6ade43cb3c0ce4525424e404f.json 
+0

沒錯剛纔我發現,太https://www.twilio.com/docs/api/ rest/response#response-formats-json ...不管怎樣,感謝回覆:) – fedrick