如何解决您如何在Java中使用PerspectiveAPI?
如何使用perspective api,在Java中,我尝试了几种代码,但效果不太好。
我已经做到了,但是没有用。
`
try {
String url = "https://commentanalyzer.googleapis.com/$discovery/rest?version=v1alpha1&",key = "key=my_key";
final URL serverUrl = new URL(url + key);
URLConnection urlConnection = serverUrl.openConnection();
HttpURLConnection httpconnection = (HttpURLConnection)urlConnection;
httpconnection.setRequestMethod("POST");
httpconnection.setRequestProperty("Content-Type","application/json");
httpconnection.setDoOutput(true);
BufferedWriter httpRequestBodyWriter = new BufferedWriter(new
OutputStreamWriter(httpconnection.getoutputStream()));
httpRequestBodyWriter.write("{\"comment\": {\"text\": \"" + "Salut mec" + "\"},"
+ "\"requestedAttributes\": {\"TOXICITY\": {}}}");
httpRequestBodyWriter.flush();
httpRequestBodyWriter.close();
System.out.println("CODE : " + httpconnection.getResponseCode());
BufferedReader responseBuffer = new BufferedReader(new InputStreamReader((httpconnection.getInputStream())));
String output;
while ((output = responseBuffer.readLine()) != null) {
System.out.println(output);
}
httpconnection.disconnect();
} catch (IOException e1) {
e1.printstacktrace();
}`
我有代码404和Caused by: java.io.FileNotFoundException: https://commentanalyzer.googleapis.com/$discovery/rest?version=v1alpha1&key=my_key
你有个主意吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。