Create Quiz Question
Updated: 2022-09-02 18:08:07
API Description
1、通过视频id创建视频的问答题目
2、接口支持https协议
API URL
http://api.polyv.net/v2/video/save-video-exam
Request Method
POST
API Constraints
- The API supports both HTTP and HTTPS. HTTPS is recommended to ensure API security. API calls have frequency limits. See details
Request Parameter Description
| Parameter | Required | Type | Description |
|---|---|---|---|
| userid | true | String | POLYV on-demand account ID. Refer to Get Secret Key for acquisition. Path: Official website -> Login -> On-Demand (API Interface) |
| ptime | true | Long | Current time in milliseconds timestamp, valid for 3 minutes |
| sign | true | String | Signature, a 40-character uppercase SHA1 value. The secretkey used to generate the signature is critical information for communication data security. It must not be saved and used directly on the client side. All APIs must be relayed through the customer's own server to call the POLYV server for response data. See Signature Generation Rules |
| vid | true | String | Video ID |
| examId | false | String | Quiz ID. If empty, a new question will be created. If not empty, the existing quiz question will be modified. |
| showTime | true | Integer | Time when the quiz appears, in seconds |
| question | true | String | Question description |
| choices | true | String | Quiz options, formatted as a JSON array object. Maximum of 5 options per question. Example: [{"index":0,"content":"a","isRight":true},{"index":2,"content":"b","isRight":false},{"index":3,"content":"c","isRight":false}] |
| canSkip | false | Boolean | Set whether the quiz can be skipped. Default is cannot skip. true: can skip false: cannot skip |
| explanationIfRight | false | String | Explanation details after answering correctly |
| showExplanationIfWrong | false | Boolean | Whether to show explanation details after answering incorrectly. Default is true. true: show false: do not show |
| explanationIfWrong | false | String | Explanation details after answering incorrectly |
| backTime | false | Integer | Time in seconds to rewind after answering incorrectly. -1 means no rewind. Default is -1 |
Example
http://api.polyv.net/v2/video/save-video-exam
Form Parameters:
vid=1b448be3231ebf0005ec631a7e4247ee_1&question=%E6%B5%8B%E8%AF%95%E5%88%9B%E5%BB%BA%E9%97%AE%E7%AD%94%E9%A2%98%E7%9B%AE%EF%BC%9F&showTime=2&sign=27D7F36E628DE0E616DBE3C48A1AECEA090C2FCF&explanationIfRight=%E7%AD%94%E5%AF%B9%E5%95%A6&canSkip=false&choices=%5B%7B%22index%22%3A0%2C%22content%22%3A%22a%22%2C%22isRight%22%3Atrue%7D%2C%7B%22index%22%3A2%2C%22content%22%3A%22b%22%2C%22isRight%22%3Afalse%7D%2C%7B%22index%22%3A3%2C%22content%22%3A%22c%22%2C%22isRight%22%3Afalse%7D%5D&userid=1b448be323&ptime=1620286349810&explanationIfWrong=%E7%AD%94%E9%94%99%E4%BA%86&backTime=1
Response Parameter Description
| Parameter | Type | Description |
|---|---|---|
| code | Integer | Response status code. 200 for success, non-200 for failure. See Global Error Description |
| status | String | Response status text information |
| message | String | Response description message. When code is 400 or 500, provides auxiliary error reason description. |
| data | Object | Returns examId on successful response. See data field description |
data Field Description
| Parameter | Type | Description |
|---|---|---|
| examId | String | Quiz ID |
Java Request Example
For quick integration of basic code, please download the relevant dependency source code. Click to download source code. After downloading, add it to your own source project. HttpUtil.java and VodSignUtil.java in the test case are included in the download file.
It is strongly recommended to use the On-Demand Java SDK for API functionality integration. The On-Demand Java SDK provides unified encapsulation and optimization for API call logic, exception handling, data signing, and HTTP request thread pools.
private static final Logger log = LoggerFactory.getLogger(VodVideoManageManagementTest.class);
/**
* 创建问答题目
*/
@Test
public void testAddQuiz() throws Exception, NoSuchAlgorithmException {
//公共参数,填写自己的实际参数
String secretKey = super.secretKey;
String userId = super.userId;
String ptime = String.valueOf(System.currentTimeMillis());
//业务参数
String url = "http://api.polyv.net/v2/video/save-video-exam";
String vid = "1b448be3231ebf0005ec631a7e4247ee_1";
String showTime = "2";
String question = "测试创建问答题目?";
String choices = "[{\"index\":0,\"content\":\"a\",\"isRight\":true},{\"index\":2,\"content\":\"b\",\"isRight\":false},{\"index\":3,\"content\":\"c\",\"isRight\":false}]";
String explanationIfRight = "答对啦";
String explanationIfWrong = "答错了";
String canSkip = "false";
String backTime = "1";
//调用参数
Map<String, String> requestMap = new HashMap<>();
requestMap.put("userid", userId);
requestMap.put("ptime", ptime);
requestMap.put("showTime", showTime);
requestMap.put("vid", vid);
requestMap.put("explanationIfRight", explanationIfRight);
requestMap.put("question", question);
requestMap.put("explanationIfWrong", explanationIfWrong);
requestMap.put("canSkip", canSkip);
requestMap.put("backTime", backTime);
requestMap.put("choices", choices);
requestMap.put("sign", VodSignUtil.getSign(requestMap, secretKey));
String response = HttpUtil.postFormBody(url,requestMap);
log.debug("测试创建问答题目,{}", response);
//do somethings
}
Response Example
For system global error descriptions, see Global Error Description
Success Example
{
"code":200,
"status":"success",
"message":"success",
"data":{
"examId":"1794097a449"
}
}
Error Example
Incorrect Signature
{
"code":400,
"status":"error",
"message":"the sign is not right",
"data":""
}
Timestamp Expired
{
"code":400,
"status":"error",
"message":"ptime is too old.",
"data":""
}
Video Not Found
{
"code": 400,
"status": "error",
"message": "video could not find by vid",
"data": ""
}
