2014-10-06 108 views
1

我试图使用我的光盘上的知识(经纬度)MySQL数据库记录从foursquare中导出类别。PHP Foursquare API返回Null到场馆/搜索

当我向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); 

除了这个问题,当我跑我的broswer代码中,我有问题:“致命错误:用C超过最长30秒的执行时间:\ XAMPP \ htdocs中\ tcc \ recomendacao \ analisarUser.php on line **$response = curl_exec($curlhandle)**

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

回答

0

看起来你的curl执行代码太慢了。

尝试最大化卷曲的执行时间并将 放在脚本的开头。

// 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); 
} 
+0

Mubo, 展位限制有助于延长出场时间,但致命错误仍然存​​在。 对我来说最陌生的是,如果我对代码进行修饰,变量$ response总是0,所以这不是我所期待的。 请问你能再帮忙吗? – 2014-10-07 23:47:51