Zend_Service_Twitter&代理后面的Zend_Oauth_Token_Access?

时间:2012-03-30 14:37:03

标签: http zend-framework proxy

我目前仍然坚持使用Zend的一些方法,我试图通过代理做一个简单的Zend_Service_Twitter请求,但是我一直在这样做:

  

无法连接到tcp://api.twitter.com:80。错误#0:   php_network_getaddresses:gethostbyname失败。

我能够自己使用Zend_Http_Client库进行http调用,所以我相信我的问题在于我将httpClient实例传递给Zend_Service_Twitter的代码......但是我猜想有足够的咆哮,基本上我有以下内容:

   $config = array(
                'adapter' => 'Zend_Http_Client_Adapter_Proxy',
                'proxy_host' => self::PROXY_HOST,
                'proxy_port' => self::PROXY_PORT,
                'timeout' => 240,
            );
$httpClient = new Zend_Http_Client(self::TWITTER_API_URL, $config);

            $token = new Zend_Oauth_Token_Access;
            $token->setParams(array(
                Zend_Oauth_Token_Access::TOKEN_PARAM_KEY => self::TWITTER_OAUTH_TOKEN,
                Zend_Oauth_Token_Access::TOKEN_SECRET_PARAM_KEY => self::TWITTER_OAUTH_TOKEN_SECRET
            ));


            $twitter = new Zend_Service_Twitter(array(
                        'username' => 'MYUSERNAME',
                        'accessToken' => $token
                    ));
            $twitter->getHttpClient($httpClient);
            $response = $twitter->account->rateLimitStatus();

任何指针都将不胜感激!

1 个答案:

答案 0 :(得分:1)

在仔细研究Zend_Service_Twitter类的同时,为了设置代理参数,您需要做的就是:

$twitter = new Zend_Service_Twitter(array(
                        'username' => 'MYUSERNAME',
                        'accessToken' => $token
                    ));

 $twitter->setLocalHttpClient($twitter->getHttpClient($httpClient));

($ httpClient是包含代理配置的Zend_Http_Client实例)