Php ZendService Twitter在客户端连接()上失败

Php ZendService Twitter在客户端连接()上失败,php,curl,twitter,zend-framework2,zend-http-client,Php,Curl,Twitter,Zend Framework2,Zend Http Client,通过ZendService/Twitter/Twitter连接Twitter API时出现问题 Error: Fatal error: Call to a member function connect() on a non-object in somepath/vendor/zendframework/zendframework/library/Zend/Http/Client.php on line 1358 $config = array ( 'ac

通过ZendService/Twitter/Twitter连接Twitter API时出现问题

Error:  Fatal error: Call to a member function connect() on a non-object in somepath/vendor/zendframework/zendframework/library/Zend/Http/Client.php on line 1358



$config = array (
                'access_token' => array (
                        'token' => 'dummy',
                        'secret' => 'dummy' 
                ),
                'oauth_options' => array (
                        'consumerKey' => 'dummy',
                        'consumerSecret' => 'dummy' 
                ),
                'http_client_options' => array (
                        'adapter' => 'Zend\Http\Client\Adapter\Curl',
                        'curloptions' => array (
                                CURLOPT_SSL_VERIFYHOST => false,
                                CURLOPT_SSL_VERIFYPEER => false 
                        ) 
                ) 
        );

        $twitter = new Twitter ( $config );
        print_r ($twitter->account->verifyCredentials ());
使用curl7.26.0(x86_64-pc-linux-gnu)OpenSSL/1.0.1e ZF 2.3.3上的PHP 5.4.35


更新1:删除访问令牌部分将返回“错误身份验证数据”消息。再次启用它将抛出致命错误:在第1358行的somepath/vendor/zendframework/zendframework/library/Zend/Http/Client.php中的非对象上调用成员函数connect(),Twitter只允许在Twitter API端点中使用SSL连接。这一细节已记录在案。因此,您需要设置适配器选项以满足SSL协议要求

试试这个:

'http_client_options' => array (
    'adapter' => 'Zend\Http\Client\Adapter\Curl',
    'curloptions' => array (
        CURLOPT_SSL_VERIFYHOST => 2,
        CURLOPT_SSL_VERIFYPEER => true,
        CURLOPT_CAINFO => '/path/to/certs/ca-bundle.pem'
    ) 
),
验证远程主机时,需要提供一个或多个受信任CA的证书。验证主机选项的值2是检查公共名称是否存在并验证其是否与提供的主机名匹配所必需的。使用1仅检查SSL对等证书中是否存在名称


您可能还想阅读更多关于在中使用Curl适配器配置SSL连接的信息。

添加引用CURLOPT_CAINFO=>'/etc/SSL/certs/ca bundle.crt'后没有任何更改。您是否尝试在生产服务器或临时服务器上运行此功能?您可能还需要为本地开发环境创建自签名证书。例如: