Shyam Agarwal
Shyam Agarwal

Reputation: 119

Integrating the IBM Watson Personality Insights API

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

Answers (1)

Vidhi
Vidhi

Reputation: 11

It is a good practose to have a valid SSL Certificate in order to get results from API. Try Following steps

  1. Go to Firefox and visit https://gateway.watsonplatform.net/personality-insights/api/v3/profile
  2. Login with your Watson PI credentials
  3. Click on the lock on left most side of the URL Bar and click on more information.
  4. Click on View Certificate -> Details
  5. The first Item in the hierarchy is your CA Certificate for IBM Watson PI, Export it to your machine.
  6. 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

Related Questions