2016-11-03 43 views
1

我正嘗試使用POST /實體請求創建實體,如api.ai文檔中的建議。 你能告訴我爲什麼實體沒有得到生成,並得到異常爲 ai.api.AIServiceException:未找到Uri或找不到提供了id的某些資源。狀態碼404,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" 
    } 
} 

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(); 
+0

任何人都可以請回復嗎? 欣賞早期回覆。 在此先感謝。 –

+0

嗨,Devendra。您是否使用開發人員訪問令牌進行請求? https://docs.api.ai/docs/entities#post-entities – xVir

+0

我遇到同樣的問題。使用Node.JS庫和開發者訪問令牌。搜索論壇,我想我也遇到了你的問題。已經有一個多月了,但仍然沒有回答......他們顯然需要一個更大的支持團隊。 – bigblind

回答

0

而不是使用客戶端訪問令牌,請使用開發人員訪問令牌。 您可以使用下面的代碼:

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); 
相關問題