gpt4 book ai didi

java - 状态码 404,ai.api.AIServiceException : Uri is not found or some resource with provided id is not found

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:26:00 25 4
gpt4 key购买 nike

我正在尝试按照 api.ai 文档中的建议使用 POST/entity 请求创建实体。你能告诉我为什么没有生成实体并出现异常吗ai.api.AIServiceException:未找到 Uri 或未找到具有所提供 ID 的某些资源。

我得到的回应是:

 {
"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"
}
}

post 请求正文中附加的 Postdata JSON:

  [{
"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();

最佳答案

不使用客户端访问 token ,而是使用开发人员访问 token 。您可以使用以下代码:

HttpClient httpClient = HttpClientBuilder.create().build();
HttpPost request = new HttpPost("https://api.api.ai/v1/entities?v=20150910");
StringEntity params =new StringEntity("{\"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\"]},{\"value\":\"Garage door\",\"synonyms\":[\"garage door\",\"garage\"]}]}");
request.addHeader("content-type", "application/json; charset=utf-8");
request.addHeader("Authorization", "Bearer 92f6b9908d8c4140a71d20059c2b773b");
request.addHeader("Accept", "application/json");
request.setEntity(params);
HttpResponse response = httpClient.execute(request);

关于java - 状态码 404,ai.api.AIServiceException : Uri is not found or some resource with provided id is not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40400655/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com