Facebook的PHP API: “没有URL集” - 随机

问题描述:

我得到这个错误在随机场合:Facebook的PHP API: “没有URL集” - 随机

Fatal error: Uncaught CurlException: 3: No URL set! 
thrown in /****/****/***/****/facebook/facebook-client/base_facebook.php on line 905 

我使用从GIT库中的最新PHP SDK(今天下载!)。发生这种情况时,用户已登录Facebook。

这种行为在2周前开始出现了。

什么可能是错误的?

更新:当我删除与域相关的所有cookie时,问题就解决了。我认为它必须对fbm_xxxxxxx和fbsr_xxxxxxxx cookie进行正确检测。但它仍然可以在“随机”场合返回,迫使我清除与该域名相关的所有Cookie。

UPDATE:

try { 
    $user_profile = $facebook->api('/me'); 
} catch (FacebookApiException $e) { 
    error_log($e); 
    $isfb = null; 
    setcookie('fbm_'.$facebook->getAppId(), '', time()-100, '/', '.mydomain.com'); 
} 

最终调用base_facebook.php这个函数:在这个块的代码发生错误

protected function makeRequest($url, $params, $ch=null) { 
    if (!$ch) { 
     $ch = curl_init(); 
    } 

    $opts = self::$CURL_OPTS; 
    if ($this->getFileUploadSupport()) { 
     $opts[CURLOPT_POSTFIELDS] = $params; 
    } else { 
     $opts[CURLOPT_POSTFIELDS] = http_build_query($params, null, '&'); 
    } 
    $opts[CURLOPT_URL] = $url; 

    // disable the 'Expect: 100-continue' behaviour. This causes CURL to wait 
    // for 2 seconds if the server does not support this header. 
    if (isset($opts[CURLOPT_HTTPHEADER])) { 
     $existing_headers = $opts[CURLOPT_HTTPHEADER]; 
     $existing_headers[] = 'Expect:'; 
     $opts[CURLOPT_HTTPHEADER] = $existing_headers; 
    } else { 
     $opts[CURLOPT_HTTPHEADER] = array('Expect:'); 
    } 

    curl_setopt_array($ch, $opts); 
    $result = curl_exec($ch); 

    if (curl_errno($ch) == 60) { // CURLE_SSL_CACERT 
     self::errorLog('Invalid or no certificate authority found, '. 
        'using bundled information'); 
     curl_setopt($ch, CURLOPT_CAINFO, 
        dirname(__FILE__) . '/fb_ca_chain_bundle.crt'); 
     $result = curl_exec($ch); 
    } 

    // With dual stacked DNS responses, it's possible for a server to 
    // have IPv6 enabled but not have IPv6 connectivity. If this is 
    // the case, curl will try IPv4 first and if that fails, then it will 
    // fall back to IPv6 and the error EHOSTUNREACH is returned by the 
    // operating system. 
    if ($result === false && empty($opts[CURLOPT_IPRESOLVE])) { 
     $matches = array(); 
     $regex = '/Failed to connect to ([^:].*): Network is unreachable/'; 
     if (preg_match($regex, curl_error($ch), $matches)) { 
      if (strlen(@inet_pton($matches[1])) === 16) { 
      self::errorLog('Invalid IPv6 configuration on server, '. 
          'Please disable or get native IPv6 on your server.'); 
      self::$CURL_OPTS[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V4; 
      curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); 
      $result = curl_exec($ch); 
      } 
     } 
    } 

    if ($result === false) { 
     $e = new FacebookApiException(array(
     'error_code' => curl_errno($ch), 
     'error' => array(
     'message' => curl_error($ch)."\n".$opts[CURLOPT_POSTFIELDS]."<br/>".$opts[CURLOPT_URL]."\n", 
     'type' => 'CurlException', 
     ), 
    )); 
     curl_close($ch); 
     throw $e; 
    } 
    curl_close($ch); 
    return $result; 
    } 

当我附和$opts[CURLOPT_POSTFIELDS]$opts[CURLOPT_URL],既postfields和网址正确设置。这可能是服务器问题吗?

更新:如果我等一些(随机数量)的时间后刷新页面,一切都很好。

+0

它可以帮助发布背景的电话吗?即什么调用Facebook类来触发错误? – Robbie 2012-07-05 23:51:15

+0

在developers.facebook.com/bugs提交错误应该可以帮助你 – phwd 2012-07-06 10:58:12

+2

你可以尝试回答你自己的问题,它对这个社区可能是非常有用的:P – 2015-11-21 19:52:42

这是关于IPv6的问题。要解决这一点,你需要包括你的Facebook API在下面的行...

if(phpversion() >= 5.3) { 
Facebook::$CURL_OPTS[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V4; 
}; 

请注意,这个替代只能最多的PHP 5.3版,所以你应该确保在您的代码版本检测。

(从西尔维奥Medice来源 - Facebook->api("/me") raises "CurlException: 3: No URL set!"