Я пытаюсь получить доступ к списку курсов udemy с помощью их партнерского API и PHP.
Я могу получить данные без проблем, если не буду использовать json_decode '.Когда я использую json_decode, я получаю эту ошибку.
'SyntaxError: JSON.parse: неожиданный символ в строке 1 столбца 1 данных JSON'
function getcourse($id)
{
header('Content-Type: application/json');
$url = "https://www.udemy.com/api-2.0/courses/$id?fields[course]=@all";
// Initiate curl
$ch = curl_init();
// Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the url
curl_setopt($ch, CURLOPT_URL,$url);
// Execute
$c_id = base64_encode('myclientid');
$c_sid = base64_encode('myclientsecretid');
curl_setopt($ch,CURLOPT_HTTPHEADER,array('X-Udemy-Client-Id: '.$c_id.'','X-Udemy-Client-Secret: '.$c_sid.'',"Authorization: base64 encoded value of client-id:client-secret","Accept: application/json, text/plain, */*"));
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
$result=curl_exec($ch);
echo curl_getinfo($ch, CURLINFO_HEADER_OUT);
echo curl_getinfo($ch,CURLINFO_HTTP_CODE);
// Closing
curl_close($ch);
$result = json_decode($result);
return $result;
}
$cdetail = getcourse(120042);
print_r($cdetail);