对Twitter API的CURL调用中的SSL错误 [英] SSL error in CURL call to Twitter API

查看:140
本文介绍了对Twitter API的CURL调用中的SSL错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我控制器的一些代码(别担心,de键是假的)。我正在使用ZendService\Twitter\Twitter模块。几乎所有东西都在工作,只有最后一个错误有点奇怪,我无法弄清楚:

Below is some code of my controller (dont worry, de keys are fake). Im using the ZendService\Twitter\Twitter module. Almost everything is working only the last error is a bit strange and i can not figure it out:

无法在TCP连接api上启用加密。 twitter.com:请确保为环境正确设置了 sslcafile或 sslcapath选项。

如您所见在我的控制器下面的代码中,您可以看到对等验证和主机验证均设置为false。适配器已经设置为Curl而不是HTTP。

As you can see i the code below of my controller, you can see that both the Verify of Peer and Host are set to false. The adapter is already set to Curl instead of HTTP.

<?php

namespace Twitter\Controller;

use QDCore\Controller\AbstractController;
use Zend\Mvc\MvcEvent;
use Zend\View\Model\JsonModel;
use ZendService\Twitter\Twitter;

class GetController extends AbstractController
{

    protected $instance;

    public function onDispatch(MvcEvent $e)
    {
        $config = array(
            'access_token' => array(
                'token' => '1024003resagsDQGyVC5YZ23423PpBNOwefS',
                'secret' => 'oES8Jergewagewahsh2hTqrYGDJo',
            ),
            'oauth_options' => array(
                'consumerKey' => 'QY360Nersehr234gg4aV2pw',
                'consumerSecret' => 'eEfgdagewa0Hkt4z6nCqHPY1M4wwuubY',
            ),
            'username' => 'myusername',
            'http_client_options' => array(
                'adapter' => 'Zend\Http\Client\Adapter\Curl',
                'curloptions' => array(
                    CURLOPT_SSL_VERIFYHOST => false,
                    CURLOPT_SSL_VERIFYPEER => false,
                ),
            ),
        );
        $this->instance = new Twitter($config);
        return parent::onDispatch($e);
    }


    public function indexAction()
    {
        $result = new JsonModel(array('message' => 'No valid function call made'));
        return $result;
    }

    public function usertimelineAction()
    {
        $options = array(
            'user_id' => 'myaccountname',
            'count' => 30,
        );
        $twitter = new Twitter($options);
        $response = $twitter->statuses->userTimeline();
        var_dump($response);
        die;
        return new JsonModel($response);
    }
}

希望有人对如何解决有想法。我的主域不在SSL上运行,也不会在SSL上运行。

Hope that someone has an idea on how to fix it. My main domain is not running on SSL and is not going to be.

谢谢

推荐答案

从不将验证主机或对等验证设置为false,除非您知道自己在做什么!

NEVER set verify host or peer verification to false, unless you know what you are doing!

您必须指出卷曲到您的认证包。对于Linux(基于Debian的系统)为 etc / ssl / certs 。您可以将其设置为 sslcapath变量:

You have to point curl to your certification bundle. For Linux (Debian based systems) that is etc/ssl/certs. You could set that as "sslcapath" variable:

'http_client_options' => array(
    'adapter' => 'Zend\Http\Client\Adapter\Curl',
    'curloptions' => array(
        'sslcapath' => '/etc/ssl/certs',
    ),
),

由于系统之间的路径不同,因此最好在 config / autoload / global.php 文件中设置它作为选项,用户可以使用 local.php 配置。在您的配置中:

Because the path varies between systems, it's good to have it as an option set in your config/autoload/global.php file which users could change with a local.php configuration. In your config:

'http_client' => array(
    'options' => array(
        'sslcapath' => '/etc/ssl/certs',
    ),
),

然后您的代码将变为:

public function onDispatch(MvcEvent $e)
{
    $app = $e->getApplication();
    $sm  = $app->getServiceManager();
    $cnf = $sm->get('Config');

    $config = array(
        'access_token' => array(
            'token' => '1024003resagsDQGyVC5YZ23423PpBNOwefS',
            'secret' => 'oES8Jergewagewahsh2hTqrYGDJo',
        ),
        'oauth_options' => array(
            'consumerKey' => 'QY360Nersehr234gg4aV2pw',
            'consumerSecret' => 'eEfgdagewa0Hkt4z6nCqHPY1M4wwuubY',
        ),
        'username' => 'myusername',
        'http_client_options' => array(
            'adapter' => 'Zend\Http\Client\Adapter\Curl',
            'curloptions' => $cnf['http_client']['options'],
        ),
    );
    $this->instance = new Twitter($config);
    return parent::onDispatch($e);
}

这篇关于对Twitter API的CURL调用中的SSL错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆