Api.ai API for php(使用 REST API 通过 POSTing)
Api.ai API for php (with REST API by POSTing)
你好,
我正在尝试将我的网络应用程序与 RESTful api 中的 php 集成。这需要我 POST 数据到 https://api.api.ai/v1/query 并且还有 2 个自定义 headers.
我当前的密码是
$data = array("v" => "20150821", "query" => "whats the time", "lang" => "EN", "sessionId" => "1234567890");
$data_string = json_encode($data);
$ch = curl_init('https://api.api.ai/v1/query');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
// 'Content-Length: ' . strlen($data_string),
'Content-type: application/json',
'Authorization: Bearer XxxX-xxx',
'ocp-apim-subscription-key: XxxX-xxx')
);
$result = curl_exec($ch);
如果我 运行 这个,(使用我的真实身份验证和密钥 obv)我什么也得不到。像空白一样。有任何想法吗?
我很抱歉。
我一直没有睡好并且犯了一个相当愚蠢的错误
我忘了 echo $result
我知道,我知道。我得小心一点
还是谢谢 :P
你好, 我正在尝试将我的网络应用程序与 RESTful api 中的 php 集成。这需要我 POST 数据到 https://api.api.ai/v1/query 并且还有 2 个自定义 headers.
我当前的密码是
$data = array("v" => "20150821", "query" => "whats the time", "lang" => "EN", "sessionId" => "1234567890");
$data_string = json_encode($data);
$ch = curl_init('https://api.api.ai/v1/query');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
// 'Content-Length: ' . strlen($data_string),
'Content-type: application/json',
'Authorization: Bearer XxxX-xxx',
'ocp-apim-subscription-key: XxxX-xxx')
);
$result = curl_exec($ch);
如果我 运行 这个,(使用我的真实身份验证和密钥 obv)我什么也得不到。像空白一样。有任何想法吗?
我很抱歉。 我一直没有睡好并且犯了一个相当愚蠢的错误 我忘了 echo $result
我知道,我知道。我得小心一点 还是谢谢 :P