0

I want to access an API provided by Lymbix sentiment via PHP. The cURL command given is

curl -H "AUTHENTICATION:MY_API_KEY" \
-H "ACCEPT:application/json" \
-H "VERSION:2.1" \
http://gyrus.lymbix.com/tonalize \
-d "article=This is a sample sentence, does it make you happy? \
&return_fields=[]"

How would I run the above in PHP?

Thank you.

2

2 Answers 2

1

I hate to feed the trolls, but i was bored. You really should do some legwork on these things first, and also accept (checkmark) answers when they are right, or got you really close.

<?php

$ch = curl_init();
$data = array('article' => 'This is a sample sentence, does it make you happy?', 'returnfields' => '[]');
$headers = array ('AUTHENTICATION'=>'MY_API_KEY','ACCEPT'=>'application/json','VERSION'=>'2.1');
curl_setopt($ch, CURLOPT_URL, "http://gyrus.lymbix.com/tonalize");
curl_setopt($ch, CURLOPT_HTTPHEADERS,$headers); 
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_exec($ch);
curl_close($ch);
?>
Sign up to request clarification or add additional context in comments.

Comments

0
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://gyrus.lymbix.com/tonalize" );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt($curl, CURLOPT_POST, true );   
curl_setopt($curl, CURLOPT_POSTFIELDS, "article=This is a sample sentence, does it make you happy?&return_fields=[]");

curl_setopt($curl, CURLOPT_HTTPHEADER, array(
    "ACCEPT:application/json\n",
    "VERSION:2.1\n",
    "AUTHENTICATION:MY_API_KEY",
));

$result = curl_exec($curl);
curl_close($curl); 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.