I am using google places API and when i request provided URL in chrome browser (on mac) than it returns more then 20 results.
But when i request same URL in PHP curl code it returns only 6 results.
Couldn't get it working. Please help.
$ch = curl_init();
$url = 'https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=31.4814662,74.411793&radius=20000&keyword='.urlencode('ac technician').'&key=API_KEY';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$response = curl_exec($ch);
echo "#####".$response; exit();
I couldn't reproduce this as your code is returning me 15 results for this same api call. I read a bit and it seems it returns only 5 results after doing many calls.
However, if you say that in a browser you get more results than in a curl call I would mimic the headers sent by the browser starting by the User-Agent
. Check if adding this works for you:
$headers = array();
$headers[] = 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
This header is copying a header that could be sent by a firefox browser.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.