我正在尝试按照 api.ai 文档中的建议使用 POST /entity 请求创建实体。你能告诉我为什么实体没有生成并得到异常为 ai.api.AIServiceException: Uri is not found or some resource with provided id is not found。
我得到的回应是:
{
"id": "d2c20de1-4a65-4b3e-8a28-48f1be009f1a",
"timestamp": "2016-11-03T11:26:18.871Z",
"status": {
"code": 404,
"errorType": "not_found",
"errorDetails": "Entity 'Appliances' is not found.",
"errorID": "12dadf38-2579-41a9-abd5-24572e64c1e4"
}
}
Postdata JSON 附加在 post 请求正文中:
[{
"name": "Appliances",
"entries": [
{
"value": "Coffee Maker",
"synonyms": [
"coffee maker",
"coffee machine",
"coffee"
]
},
{
"value": "Thermostat",
"synonyms": [
"Thermostat",
"heat",
"air conditioning"
]
},
{
"value": "Lights",
"synonyms": [
"Lights",
"Light",
"lamps"
]
}
]
}
]
Java 代码片段:
HttpURLConnection connection = null;
final URL url = new URL(endpoint);
final String postJsonData = requestJson;
Log.debug("Request json: " + postJsonData);
System.out.println(postJsonData);
if (config.getProxy() != null) {
connection = (HttpURLConnection) url.openConnection(config.getProxy());
} else {
connection = (HttpURLConnection) url.openConnection();
}
//post request
connection.setRequestMethod("POST");
connection.addRequestProperty("Authorization", "Bearer " + config.getApiKey());
connection.addRequestProperty("Content-Type", "application/json; charset=utf-8");
connection.addRequestProperty("Accept", "application/json");
connection.setDoOutput(true);
connection.connect();
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
wr.writeBytes(postJsonData);
wr.flush();
wr.close();
int responseCode = connection.getResponseCode();
BufferedReader in = new BufferedReader(
new InputStreamReader(connection.getInputStream()));
String output;
StringBuffer response = new StringBuffer();
while ((output = in.readLine()) != null) {
response.append(output);
}
in.close();