php - Facebook PHP API : "no url set" - random

标签 php facebook api sdk

我在随机 场合遇到此错误:

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。

更新:错误发生在这段代码上:

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 和 URL 都设置正确。有没有可能是服务器问题?

更新:如果我等待一段时间(随机时间)后刷新页面,一切都会恢复正常。

最佳答案

这与 IPv6 的问题有关。要解决此问题,您需要在 Facebook API 中包含以下行...

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

请注意,此替代方案仅适用于 PHP 5.3 版本,因此您应确保在代码中包含版本检测。

(来自 Silvio Medice - Facebook->api("/me") raises "CurlException: 3: No URL set!")

关于php - Facebook PHP API : "no url set" - random,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11353463/

相关文章:

php - 使用加密邮箱地址、用户名作为退订链接

php - 如何从 Wordpress RSS Feed 的自定义分类术语中排除帖子

php - Magento 1.9 中的类别页面未显示 SSL。其余所有页面,包括主页和产品页面都工作正常

Facebook Drupal(fboauth)弹出窗口以全屏方式打开

c - Spotify 将 C 更改为 VB.net

php - MySQL 插入查询优化

facebook - 您最想复制或最受欢迎的 Web API 是什么?

java - Maven 存储库有无效的 java.lang.IllegalStateException

api - Spring Security 中接收 token 的基本身份验证

android - Android 上的 Facebook 单点登录 (SSO) 在激活时关闭 Intent