【问题标题】:Facebook SDK cURL and SSL ErrorFacebook SDK cURL 和 SSL 错误
【发布时间】:2012-06-22 07:56:35
【问题描述】:

我尝试为我的网站使用 facebook API。 但是我遇到了这样的错误

致命错误:未捕获的 CurlException:1:不支持协议 https 或在 libcurl 中禁用 /home/batav1/public_html/permaisuri/include/fbsdk/src/base_facebook.php 887行

我在输入 phpinfo() 时检查了 curl 配置,结果如下

cURL support enabled
cURL Information libcurl/7.21.0 zlib/1.2.3 libidn/0.6.5

我该怎么办? 这是我的代码:

<?php
require 'include/fbsdk/src/facebook.php';
$facebook = new Facebook(array(
  'appId'  => '33025497038xxxx',
  'secret' => '87be6ab5175a9be7c7d48be74dd5xxxx',
));

$user = $facebook->getUser();

if ($user) {
  try {
    // Proceed knowing you have a logged in user who's authenticated.
    $user_profile = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
  }
}

if ($user) {
  $logoutUrl = $facebook->getLogoutUrl();
} else {
  $loginUrl = $facebook->getLoginUrl();
}

$naitik = $facebook->api('/naitik');

?>
<!doctype html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
  <head>
    <title>php-sdk</title>
    <style>
      body {
        font-family: 'Lucida Grande', Verdana, Arial, sans-serif;
      }
      h1 a {
        text-decoration: none;
        color: #3b5998;
      }
      h1 a:hover {
        text-decoration: underline;
      }
    </style>
  </head>
  <body>
    <h1>php-sdk</h1>

    <?php if ($user): ?>
      <a href="<?php echo $logoutUrl; ?>">Logout</a>
    <?php else: ?>
      <div>
        Login using OAuth 2.0 handled by the PHP SDK:
        <a href="<?php echo $loginUrl; ?>">Login with Facebook</a>
      </div>
    <?php endif ?>

    <h3>PHP Session</h3>
    <pre><?php print_r($_SESSION); ?></pre>

    <?php if ($user): ?>
      <h3>You</h3>
      <img src="https://graph.facebook.com/<?php echo $user; ?>/picture">

      <h3>Your User Object (/me)</h3>
      <pre><?php print_r($user_profile); ?></pre>
    <?php else: ?>
      <strong><em>You are not Connected.</em></strong>
    <?php endif ?>

    <h3>Public profile of Naitik</h3>
    <img src="https://graph.facebook.com/naitik/picture">
    <?php echo $naitik['name']; ?>
  </body>
</html>

【问题讨论】:

    标签: php facebook


    【解决方案1】:

    您的 php 设置似乎不支持 https 包装器

    要允许 https 包装器:- php_openssl 扩展必须存在并启用 - allow_url_include 必须设置为 on

    如果不存在,请在 php.ini 文件中添加以下行:

    extension=php_openssl.dll
    
    allow_url_include = On
    

    【讨论】:

    • 他正在使用 curl,所以不需要 allow_url_include。
    • 你使用的是 windows dll,而根据错误及其 /home/.. 路径我猜他是在 linux/unix 变体上......
    【解决方案2】:

    问题是 curl 扩展没有编译 ssl 支持。您应该使用选项 --with-curl 和 --with-openssl 重新编译 PHP。

    希望对您有所帮助。

    【讨论】:

    • 我检查了我的命令,似乎 --with-curl 已经执行了。 --with-openssl 也应该执行吗?
    猜你喜欢
    • 1970-01-01
    • 2011-11-15
    • 1970-01-01
    • 2017-04-22
    • 2018-07-12
    • 2017-10-02
    • 2017-01-20
    • 2012-09-17
    • 2016-09-23
    相关资源
    最近更新 更多