Reputation: 119
I am building a Web App and want to integrate the IBM Watson Personality Insights API. I am using PHP and would have to use Curl Library for the same
Below is the code which is mentioned in the IBM documentation for using Curl
curl -X POST --user {username}:{password}
--header "Content-Type: text/plain;charset=utf-8"
--header "Accept: application/json"
--data-binary @<filename>
"https://gateway.watsonplatform.net/personality-insights/api/v3/profile"
How do I do this in PHP?
I am trying to do this but i am getting an empty response
$ch2 = curl_init("https://gateway.watsonplatform.net/personality-insights/api/v3/profile");
$request_headers = array();
$request_headers[] = 'Content-Type: text/plain;charset=utf-8';
$request_headers[] = 'Content-Language: en';
$request_headers[] = 'Accept-Language: en';
$simple_data = 'Some dummy data';
curl_setopt_array( $ch2, array(
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $simple_data,
CURLOPT_HTTPHEADER => $request_headers,
CURLOPT_USERPWD => 'XXXX:YYYY',
)
);
$response2 = curl_exec( $ch2 );
Upvotes: 0
Views: 498
Reputation: 11
It is a good practose to have a valid SSL Certificate in order to get results from API. Try Following steps
Then Just Use this 3 line of Code within your Curl Request
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO , getcwd() . "\Your Certificate Location");
Upvotes: 1