So I need to use the Twitter REST API in a web application I’m developing and I have written some very basic PHP code to just test whether or not I can connect to the Twitter Server. Unfortunately, whenever I try to execute the code, it crops up with an error:
Fatal error: Uncaught exception ‘Exception’ with message ‘SSL certificate problem: unable to get local issuer certificate’
I am hosting the application currently on XAMPP 3.2.2 as a testing front so it’s not officially hosted anywhere as of yet.
Here is my code with the exception of my consumer key and oauth token as they’re confidential:
<?php
require_once("TwitterAPIExchange.php");
$url = "https://api.twitter.com/1.1/search/tweets.json";
$twitter = new TwitterAPIExchange($settings);
$requestMethod = "GET";
$getField = "?q=twitter";
$response = $twitter->setGetfield($getField)->buildOauth($url, $requestMethod)->performRequest();
echo $response;
?>
How can I solve the SSL certificate problem? I’m not very knowledgeable about SSL and I need it to use this API in my web app.
As I’ve said before, I have entered my oauth and consumer details but not here as that’s private information
Thanks in advance
4
Answers
You need to set up the CURL library to use a “CA certificates” file (commonly known as cacert.pem).
Basically you need to alter php.ini (example).
It’s not recommanded, but you can alter the library and disable the CURL SSL.
On line 296, add this:
CURLOPT_SSL_VERIFYPEER => false
That should work.
enter image description here
Hope it helps.
The correct answer is:
Reason being, they merge the 2nd parameter on
performRequest
with their options they pass to curlXAMP has had issue with outdated root/chain certificate in curl for ages now.
If you are free to use another tool, I would suggest switching to Laragon