In 'Your Active Web Service list' click on the application name to
have access to subscription details, including the PublicAccessID
and the SecretAuthKey
Replace the PublicAccessID and SecretAuthKey in the code snippet below
with yours data.
The PublicAccessID key is sent as clear text, and is used to identify
both user and application. Our platform uses an hash based verification system
to check the data integrity and the user identity.
The SecretAuthKey is only used locally to generate the hash, and it's
never transmitted over the network. You never have to send it. Keep it secret!
<?php
$input = "What a fabulous hotel, the dinner was excellent.";
$langID = "en";
$xmlResponse = wsSentAnalysisExample($input, $langID);
$xmlObject = simplexml_load_string($xmlResponse);
// Do something here with the result
function wsSentAnalysisExample($text, $langID) {
$wsServiceCode = 'nlp:sen:v1';
$pText = $text;
$pLangID = $langID;
$publicAccessID = '0123456789012345678901234567890123456789012345678901234567890123';
$secretAuthKey = '9876543210987654321098765432109876543210987654321098765432109876';
$strToHash = $wsServiceCode . $pText . $pLangID;
$authWSControlKey = hash_hmac('sha256', $strToHash, $secretAuthKey);
$data = array(
'pText' => $pText,
'pLangID' => $pLangID,
'publicAccessID' => $publicAccessID,
'authWSControlKey' => $authWSControlKey
);
$data = http_build_query($data);
// US-Location Endpoint
$endPoint = "http://us.ws.intellexere.com/core/nlp/sen/v1";
// EU-Location Endpoint
// $endPoint = "http://eu.ws.intellexere.com/core/nlp/sen/v1";
$reply = do_post_request($endPoint, $data);
return($reply);
}
function do_post_request($url, $data, $optional_headers = null) {
$params = array('http' => array(
'method' => 'POST',
'content' => $data
));
if ($optional_headers !== null) {
$params['http']['header'] = $optional_headers;
}
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Error: $url, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Error: $url, $php_errormsg");
}
return $response;
}
?>