PHP Foursquare API对场馆/搜索返回Null


PHP Foursquare API returns Null to venues/search

我正试图使用光盘上的知识(lat,long)MySQL数据库记录从foursquare导出类别。

当我请求foursquare时,我只收到NULL,而不是预期的数据。

遵循代码:

        $id = $_SESSION["id"];
        $total = $resultA["place"];
        $lat = addslashes($resultA["place_lat"]);
        $lng = addslashes($resultA["place_lng"]);
        $name = addslashes($resultA["place_name"]);
            $client_key = 'client_id';
            $client_secret = 'client_secret';
            $curlhandle = curl_init();
            curl_setopt($curlhandle, CURLOPT_URL, "https://api.foursquare.com/v2/venues/search
                            ?client_id=client_id
                            &client_secret=client_secret
                            &v=20141006
                            &ll=$lat,$lng");
            curl_setopt($curlhandle, CURLOPT_RETURNTRANSFER, 1);
            **$response = curl_exec($curlhandle)**;
            curl_close($curlhandle);
            $venues = json_decode($response);

除了这个问题,当我在浏览器上运行代码时,我还遇到了一个问题:"致命错误:在C:''examplep''htdocs''tcc''recommendacao''analisarUser.php的**$response = curl_exec($curlhandle)**行超过了30秒的最大执行时间"

有人知道会发生什么?非常感谢。

您的curl似乎太慢,无法执行代码。

尽量最大化curl to和put的执行时间这是在你的剧本开头。

  // if you set it to 0 , it mean the limit to
  // infinite, maximum available limit.
    ini_set('MAX_EXECUTION_TIME', 0);
   //Or give it a limit on your wish
   ini_set('MAX_EXECUTION_TIME', 500);

希望这能帮助你

您可以进一步尝试将try-catch块添加到代码中,以便抛出异常。

$id = $_SESSION["id"];
$total = $resultA["place"];
$lat = addslashes($resultA["place_lat"]);
$lng = addslashes($resultA["place_lng"]);
$name = addslashes($resultA["place_name"]);
$client_key = 'client_id';
$client_secret = 'client_secret';
try {

        $client_key = 'client_id';
        $client_secret = 'client_secret';
        $curlhandle = curl_init();
        curl_setopt($curlhandle, CURLOPT_URL, "https://api.foursquare.com/v2/venues/search
                        ?client_id=client_id
                        &client_secret=client_secret
                        &v=20141006
                        &ll=$lat,$lng");
        curl_setopt($curlhandle, CURLOPT_RETURNTRANSFER, 1);
    $response = curl_exec($curlhandle);
    if($response !== FALSE):
    curl_close($curlhandle);
    $venues = json_decode($response);
    endif;
}
catch(Exception $ex){
    throw new Exception("Invalid URL",0,$ex);
}