Skip to content

Commit de597c4

Browse files
committed
add new example for query videCensorResult after videoCesnor [ci skip]
1 parent 10accea commit de597c4

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

examples/ResourcesCensor.java

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,16 @@ public static void main(String args[]) {
2020
ResourcesCensor resourcesCensor = new ResourcesCensor();
2121
String result;
2222
try {
23-
result = resourcesCensor.ImageCensor();
24-
//result = resourcesCensor.VideoCensor();
25-
System.out.printf(result);
23+
//result = resourcesCensor.ImageCensor();
24+
result = resourcesCensor.VideoCensor();
25+
System.out.println(result);
26+
27+
/* 只有视频审核才会返回jobID */
28+
Gson gson = new Gson();
29+
Map<String, String> jobMap = new HashMap();
30+
String jobID = (String) gson.fromJson(result, jobMap.getClass()).get("job");
31+
String videoCensorResult = resourcesCensor.getVideoCensorResultByJobID(jobID);
32+
System.out.println(videoCensorResult);
2633
} catch (QiniuException e) {
2734
e.printStackTrace();
2835
}
@@ -88,13 +95,33 @@ public String VideoCensor() throws QiniuException {
8895
return post(url, bodyByte);
8996
}
9097

98+
/**
99+
*
100+
* @param ID : 视频审核返回的 job ID
101+
*
102+
*/
103+
public String getVideoCensorResultByJobID(String ID){
104+
String url = "http://ai.qiniuapi.com/v3/jobs/video/".concat(ID);
105+
String accessToken = (String) auth.authorizationV2(url).get("Authorization");
106+
StringMap headers = new StringMap();
107+
headers.put("Authorization", accessToken);
108+
109+
try {
110+
com.qiniu.http.Response resp = client.get(url,headers);
111+
return resp.bodyString();
112+
} catch (Exception e) {
113+
e.printStackTrace();
114+
}
115+
return null;
116+
}
117+
91118
private String post(String url, byte[] body) throws QiniuException {
92119
String accessToken = (String) auth.authorizationV2(url, "POST", body, "application/json")
93120
.get("Authorization");
94121

95122
StringMap headers = new StringMap();
96123
headers.put("Authorization", accessToken);
97-
124+
98125
com.qiniu.http.Response resp = client.post(url, body, headers, Client.JsonMime);
99126
return resp.bodyString();
100127
}

0 commit comments

Comments
 (0)