我是PHP的程序员新手,我有Macbook Pro所以我已经为它安装了mamp并且一切运行良好,而现在我正在使用xampp和相同的程序在xampp中不起作用。
计划如下:
<?php
require_once('TwitterAPIExchange.php');
/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array(
'oauth_access_token' => "47w756hhd7jBU0yXqOfeJQKlgXYD",
'oauth_access_token_secret' => "YjhdfhUE1hYaNu5E4IiU0gZnqt1kp5nSUy1lP",
'consumer_key' => "878bdfdffhEOXx5AdJhpelO9ZNStb",
'consumer_secret' => "jhfhrhXjJ867vvIRSwsI6CJuhUIEYoj0iGHGNpIPkXJ3lcTP9W"
);
$url = "https://api.twitter.com/1.1/search/tweets.json";
$requestMethod = "GET";
$getfield = '?q=#varanasi&result_type=recent';
//this code converts json code into simple string object
$twitter = new TwitterAPIExchange($settings);
$string = json_decode($twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest(),$assoc = TRUE);
echo $string;
if($string["errors"][0]["message"] != "") {
echo "<h3>Sorry, there was a problem.</h3><p>Twitter returned the following error message:</p><p><em>".$string[errors][0]["message"]."</em></p>";
exit();
}
echo "<pre>";
print_r($string);
echo "</pre>";
if(empty($string))
{
echo "hello there is nothing";
}
else
{
echo "hello everything:";
}
?>
现在$string
在xampp中显示空数据,而在mamp中它运行良好。
答案 0 :(得分:0)
我通过编辑TwitterAPIExchange.php文件解决了这个问题。 只需添加
CURLOPT_SSL_VERIFYPEER =&gt;假
在performRequest方法的$ options数组