0
我正在嘗試向RingCentral API發送一個請求來觸發SMS消息發送。我已閱讀文檔,看起來好像我以正確的格式發佈了所有數據,但出現「不支持的介質類型」錯誤。RingCentral REST API發佈數據的正確方法?
有沒有人看到我的代碼有什麼問題,或者是否有任何人對此API有過使用經驗?
$data = array("from" => "+10000000000", "to" => "+100000000", "text" => "test_sms_message");
$data_string = json_encode($data);
$ch = curl_init('https://platform.devtest.ringcentral.com/restapi/v1.0/account/~/extension/~/sms');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = array();
$headers[] = "Authorization: Bearer ".$auth_token;
$headers[] = "Accept: application/json";
$headers[] = "Content-Type: application/x-www-form-urlencoded";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
print_r($result);
我對這個API一無所知,但很可能你的意思是'Content-Type:application/json'。當你發送一個請求時(至少如果API正確地遵循HTTP規範),'Accept'頭部不會做任何事情。 – Cfreak
實際上它就是這樣!謝謝你,我花了很長時間來修補這個問題,試圖讓它正確無誤!我非常感謝你的幫助。 –
作爲參考,RingCentral官方的PHP SDK在這裏是https://github.com/ringcentral/ringcentral-php,這裏有一個非官方的社區SDK https://github.com/grokify/ringcentral-sdk-php-lite – Grokify