Failed to connect to IBM Language Translation through PHP cURL

0

I have a problem that I can not resolve. Basically I need to translate a string into English for English . This is the code I was able to develop:

<?php
    class CtrlTranslate{
        public function translate($text) {
            $url = "https://gateway.watsonplatform.net/language-translation/api";

            $user = "[user]";
            $password = "[password]";

            $post_args = array(
                'model_id' => 'pt-en',
                'text' => $text
            );

            $handle = curl_init($url);
            $header_args = array(

                'Content-Type: text/plain',
                'Accept: application/json'
            );

            curl_setopt($handle, CURLOPT_POST, true);
            curl_setopt($handle, CURLOPT_HTTPHEADER, $header_args);
            curl_setopt($handle, CURLOPT_POSTFIELDS, $post_args);
            curl_setopt($handle, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
            curl_setopt($handle, CURLOPT_USERPWD, $user.":".$password);
            curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
            $response = curl_exec($handle);
            $responseDecoded = json_decode($response, true);
            curl_close($handle);

            return $responseDecoded;
        }
    }
?>
    
asked by anonymous 09.09.2016 / 17:59

0 answers