这个问题已被多次询问,我尝试了大部分解决方案,但没有任何方法对我有用。
我想在我的网站上显示Instagram上最受欢迎的照片。我已经设法从Instagram获取图像,但我无法解码响应。以下是我的代码。
function makeRequest($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //to suppress the curl output
$response = curl_exec($ch);
curl_close ($ch);
$response = json_decode($response, true);
return $response;
}
print_r(makeRequest('https://api.instagram.com/v1/media/popular?client_id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'));
上面的代码提供了“ JSON_ERROR_UTF8 ”错误。
我尝试过以下解决方案,它会出现“ JSON_ERROR_SYNTAX ”错误。
$response = iconv('UTF-8', 'UTF-8//IGNORE', utf8_encode($response));
$json = json_decode(html_entity_decode($response, true));
我也尝试过以下解决方案,但我收到了“ JSON_ERROR_UTF8 ”错误。
$headers = array('Content-Type: application/json; charset=UTF-8');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
任何人都可以指出我做错了什么吗?
提前致谢。
更新:响应可以在以下链接中找到。