所以我正在尝试将我的应用程序与facebook集成,我使用默认的example.php代码作为我的index.php。我已经更改了appID和appSecret以匹配我的应用程序的id和秘密,每当我在facebook上测试代码时,它都会抛出异常,即UnhandledCurlException。使用try和catch来编写代码只会在调用getUser()方法时返回0。
我知道我可以在php.ini上启用curl扩展,但我只能在我的本地主机上找到它,但不能在我用来部署我的应用程序的服务器(000webhost.com)上找到它。
我也听说可以使用.htaccess文件来明确修改php配置,从而启用curl扩展,任何人都知道如何做到这一点?还是有其他我错过的选择?
这是抛出错误的函数: 受保护的函数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);
$errno = curl_errno($ch);
// CURLE_SSL_CACERT || CURLE_SSL_CACERT_BADFILE
if ($errno == 60 || $errno == 77) {
self::errorLog('Invalid or no certificate authority found, '.
'using bundled information');
curl_setopt($ch, CURLOPT_CAINFO,
dirname(__FILE__) . DIRECTORY_SEPARATOR . 'fb_ca_chain_bundle.crt');
$result = curl_exec($ch); //the line 1003
}
// 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),
'type' => 'CurlException',
),
));
curl_close($ch);
throw $e;
}
curl_close($ch);
return $result;
}
答案 0 :(得分:2)
首先确保使用此代码是否真正配置了 cURL
扩展程序。
<?php
echo function_exists('curl_version') ? 1:0; // 1 = enabled , 0 = disabled.
如果已禁用,请让您的网站托管服务提供商启用该扩展程序。 [我认为这不是一件很难的事情,而是在他们不知情的情况下使用 .htaccess
和其他方法来启用cURL
。 ]