2011-02-01 43 views
0

我想通過PHP訪問由Lymbix情緒提供的API。給出的cURL命令是cURL問題:我如何在PHP中運行這個?

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=[]" 

我該如何在PHP中運行上述代碼?

謝謝。

+1

我會轉到這裏開始可能做錯了。 – sberry 2011-02-01 04:57:20

回答

1

我討厭喂巨魔,但我很無聊。你應該首先在這些事情上做點修改,並且在他們是對的時候接受(複選標記)答案,或者讓你真的很接近。 http://php.net/manual/en/book.curl.php,嘗試寫一些代碼,然後回來,問具體問題關於你:

<?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); 
?> 
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);