PHP (Xampp vs Mamp)


PHP (Xampp vs Mamp)

我是一名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中它工作得很好。

我已经通过编辑TwitterAPIExchange.php文件解决了这个问题。只是添加

CURLOPT_SSL_VERIFYPEER => false

performRequest方法中的$options数组