ZendService Twitter 在 Client connect() 上失败


ZendService Twitter fails on Client connect()

通过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 ());

Using curl 7.26.0 (x86_64-pc-linux-gnu) OpenSSL/1.0.1ePHP 5.4.35 在 ZF 2.3.3 上

更新 1:删除access_token部分将返回"错误的身份验证数据"消息。再次启用它,将抛出 atal 错误:在第 1358 行的某个路径/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 的证书。VERIFYHOST选项的值 2 是检查公用名是否存在所必需的,并验证它是否与提供的主机名匹配。使用 1 仅检查 SSL 对等证书中是否存在名称。

您可能还想在这个不错的教程中阅读有关使用 Curl 适配器配置 SSL 连接的更多信息。