duanlinjian5819 2012-07-05 22:37
浏览 52

Facebook PHP api:“没有网址设置” - 随机

I get this error on random occasions:

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

I am using the latest php sdk from the GIT repository (downloaded today!). The user is already logged in facebook when this happens.

This behavior started 2 weeks ago out of the blue.

What can be wrong?

UPDATE: When I delete all cookies associated with the domain, the problem is resolved. I think it has to do something with fbm_xxxxxxx and fbsr_xxxxxxxx cookies not being detected correctly. However it can still return at "random" occasions, forcing me to clear all the cookies associated with that domain.

UPDATE: the error occurs on this chunk of code:

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

which eventually calls this function in 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)."
".$opts[CURLOPT_POSTFIELDS]."<br/>".$opts[CURLOPT_URL]."
",
        'type' => 'CurlException',
        ),
      ));
      curl_close($ch);
      throw $e;
    }
    curl_close($ch);
    return $result;
  }

When I echoed $opts[CURLOPT_POSTFIELDS] and $opts[CURLOPT_URL] , both postfields and URL were set properly. Is it possible it's a server issue?

UPDATE: if I wait after some (random amount of) time and refresh the page, everything is fine again.

  • 写回答

1条回答 默认 最新

  • dongxiji0687 2016-02-03 13:10
    关注

    This is to do with problems with IPv6. To resolve this you need to include the following line in your Facebook API...

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

    Please note this alternative only works up to version 5.3 of PHP so you should make sure to include the version detection in your code.

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

    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看