0

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

在 ZF 2.3.3 上使用 curl 7.26.0 (x86_64-pc-linux-gnu) OpenSSL/1.0.1e PHP 5.4.35

更新 1:删除 access_token 部分会返回“错误的身份验证数据”消息。再次启用它,将引发 atal 错误:Call to a member function connect() on a non-object in somepath/vendor/zendframework/zendframework/library/Zend/Http/Client.php on line 1358

4

1 回答 1

1

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 的证书。option的值 2VERIFYHOST是检查公用名是否存在以及验证它是否与提供的主机名匹配所必需的。使用 1 仅检查 SSL 对等证书中是否存在名称。

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

于 2014-11-21T09:17:46.627 回答