Search code examples
phpxamppmamp

PHP (Xampp vs Mamp)


I am new as a programer in PHP, I have Macbook Pro so I have installed mamp for it and it all worked well while now I am using xampp and same program not working in xampp.

Program is as follows:

<?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:";
}
?>

Now the $string is showing empty data in xampp while in mamp it is all working well.


Solution

  • I've solved this by editing TwitterAPIExchange.php file. Just adding

    CURLOPT_SSL_VERIFYPEER => false

    at the $options array at the performRequest method