我正在尝试使用TwitterAPIExchange搜索Twitter,但它给出以下错误:
Fatal error: Uncaught exception 'Exception' with message 'couldn't
connect to host' in [...]/TwitterAPIExchange.php:305 Stack trace: #0
[...]/tweet.php(19): TwitterAPIExchange->performRequest() #1 {main} thrown
in [...]/teamwatch/TwitterAPIExchange.php on line 305
在这个阶段,我真的不关心MITM攻击,所以我遵循了其他stackoverflow问题中的建议并添加了curl选项CURLOPT_SSL_VERIFYPEER => 假,但结果未更改。
所以我不明白我的脚本有什么问题。
<?php
require_once('TwitterAPIExchange.php');
$settings = array(
'oauth_access_token' => "*****************",
'oauth_access_token_secret' => "*****************",
'consumer_key' => "*****************",
'consumer_secret' => "*****************"
);
$url = 'https://api.twitter.com/1.1/search/tweets.json';
$getfield = '?q=%40twitterapi';
$requestMethod = 'GET';
$options = array( CURLOPT_SSL_VERIFYPEER => false );
$twitter = new TwitterAPIExchange($settings);
echo $twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest(true, $options);
?>
问题是主机上缺少卷曲...代码很好。