How to convert IBM Watson cURL commands to PHP How to convert IBM Watson cURL commands to PHP wordpress wordpress

How to convert IBM Watson cURL commands to PHP


After a few attempts, I was able to make the code work using my Custom Classifier Model of IBM Watson Visual Recognition.

Change {your_api_key} to your credential and {your_custom_model_ID} to your custom model ID.

The Code:

<?php// Code Date: March, 2018// === Remember to see all documentation in IBM Watson ===// Set the endpoint URL$url = 'https://gateway-a.watsonplatform.net/visual-recognition/api/v3/classify?api_key={your_api_key}&version=2016-05-20';// Set the image url$image_url = '&url=http://completeURL.com/img.jpg';// Set my custom classifier$classifier = '&classifier_ids={your_custom_model_ID}';// Set the Threshold, by default is 0.5 - To show all scores use Zero$threshold = '&threshold=0';//cURL$ch = curl_init();    curl_setopt($ch, CURLOPT_URL, $url); //Endpoint URL    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);    curl_setopt($ch, CURLOPT_POST, 1); //POST    curl_setopt($ch, CURLOPT_POSTFIELDS, $image_url . $classifier . $threshold); //Parameters// Execute the cURL command$result = curl_exec($ch);// Erroif (curl_errno($ch)) {    echo 'Error: ' . curl_error($ch);}// Close the commandcurl_close ($ch);// Show the JSON resultecho $result;

Especial thanks to Samvel Aleqsanyan for your attention.