【发布时间】:2015-12-28 21:07:21
【问题描述】:
我正在尝试使用 callfire REST API 发出出站呼叫,但在执行此操作时遇到了一些困难。这是我的代码(改编自https://developers.callfire.com/docs.html#createVoiceBroadcast):
<?php
$username = '...';
$password = '...';
$data = array(
'name' => 'Automation Test',
'fromNumber' => '...',
'recipients' => array(
array('phoneNumber' => '...')
),
'answeringMachineConfig' => 'AM_AND_ALIVE',
'liveSoundText' => 'hello, world!',
'machineSoundText' => 'hello, world!'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://api.callfire.com/v2/campaigns/voice-broadcasts');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$result = json_decode(curl_exec($ch));
print_r($result);
问题在于响应。如下:
stdClass Object
(
[httpStatusCode] => 415
[internalCode] => 0
[message] => Exception in API
)
415 状态代码是针对 https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#4xx_Client_Error 的“不支持的媒体类型”,但由于我没有上传任何媒体,因此该错误并没有多大意义。
也许我对answeringMachineConfig 的值无效。我知道 AM_AND_LIVE 应该是什么意思,但它在示例中,所以我正在使用它。如果只有少数可能的值,文档应该这样说..
【问题讨论】: