Skip to content

Instantly share code, notes, and snippets.

@vpekar
Last active February 3, 2016 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vpekar/0b527032a43ab9d73ff0 to your computer and use it in GitHub Desktop.
Save vpekar/0b527032a43ab9d73ff0 to your computer and use it in GitHub Desktop.
<?php
$ch = curl_init();
$headers = array("Content-Type: application/x-www-form-urlencoded; charset=UTF-8",
"<ACCESS-KEY-HEADER>: <ACCESS-KEY>");
curl_setopt($ch, CURLOPT_URL, "<ACCESS-URL>");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$fields = array('text'=>"The food was great, but the service was slow.", 'lang'=>'en',
'keywords' =>1, 'sentiment'=>1, 'annotate'=>1);
$postvars = '';
foreach($fields as $key=>$value) {
$postvars .= $key . "=" . $value . "&";
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
echo $response;
curl_close($ch);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment