ZendService_Twitter icon indicating copy to clipboard operation
ZendService_Twitter copied to clipboard

HTTP client options not honoured when calling getAccessToken

Open SteveTalbot opened this issue 11 years ago • 5 comments

When a Twitter object is first instantiated, an HTTP client is created, using the http_client_options specified in the array passed into the constructor. So for example, if you want to use curl as your HTTP adapter, you can do something like this:

$config = array(
    'oauth_options' => array(
        'consumerKey' => 'twitter-consumer-key-here',
        'consumerSecret' => 'twitter-consumer-secret-here',
    ),
    'http_client_options' => array(
        'adapter' => 'Zend\Http\Client\Adapter\Curl',
        'curloptions' => array(
             CURLOPT_CAINFO => 'path-to-ca-cert-here',
        )
    ),
);
$twitter = new Twitter($config);

When getAccessToken() is called, the HTTP client is replaced and the http_client_options are not honoured. This means the default stream adapter will be used instead of curl.

The problem seems to be on line 219 of ZendService\Twitter\Twitter.php, but I've been trying for ages and can't find an elegant solution:

$this->setHttpClient($return->getHttpClient($this->options));

SteveTalbot avatar Jan 24 '14 18:01 SteveTalbot

The same problem arises also with getRequestToken. I guess the problem it that getAccessToken/getRequestToken are forwarded to the Consumer which isn't forwarded any http_client_options/http_client.

Even setting http_client manually is ignored.

The issue is blocking on my project as the class Socket fails because sslverifypeer = true and I'm not able to disable it.

giulioprinaricotti avatar Apr 17 '14 10:04 giulioprinaricotti

I ended up setting the httpClient globally for OAuth using OAuth::setHttpClient()

$config = array(
                   'adapter'   => 'Zend\Http\Client\Adapter\Curl',
                    'curloptions' => array(
                            CURLOPT_SSL_VERIFYHOST => false,
                            CURLOPT_SSL_VERIFYPEER => false
                    ),
                 );
$httpClient = new HttpClient(null,$config);
OAuth::setHttpClient($httpClient);

The same $httpClient is given to Twitter() as http_client option

Does anyone have a more elegant solution?

giulioprinaricotti avatar Apr 17 '14 11:04 giulioprinaricotti

@giulioprinaricotti Looks like a neat approach

SteveTalbot avatar Apr 17 '14 15:04 SteveTalbot

@SteveTalbot thank you. Only drawback I see is that you have to repeat it every time it is needed and setting something global is always a source of problems.

giulioprinaricotti avatar Apr 17 '14 15:04 giulioprinaricotti

This repository has been closed and moved to laminas/laminas-twitter; a new issue has been opened at https://github.com/laminas/laminas-twitter/issues/2.

weierophinney avatar Dec 31 '19 22:12 weierophinney