云录制 RESTful API 请求示例

更多云端录制相关链接:
【云端录制】常见集成问题集锦

目录

  • 1,先创建一个用于录制测试的频道,频道内至少包含一个有效发流的客户端
  • 2,获取recourseId
    • 使用postman请求
    • curl命令 请求示例
    • php 请求示例
    • Java post请求示例(仅供参考)
  • 3,开始录制
    • 使用postman 请求
  • 4,查询录制情况
    • 使用postman请求
  • 5,停止录制
    • 使用postman 请求
  • 6,云平台查看上传情况

特别说明:

1,云录制目前支持合流录制,https://docs.agora.io/cn/cloud-recording/product_cloud_recording?platform=Linux
2,参照文档获取你声网账户下的CustomerID和Customer Certificate:https://docs.agora.io/cn/cloud-recording/cloud_recording_api_rest?platform=All%20Platforms#a-nameautha认证
3,官网文档:https://docs.agora.io/cn/cloud-recording/cloud_recording_rest?platform=All%20Platforms#上传和管理录制文件
4,错误码:https://docs.agora.io/cn/cloud-recording/cloud_recording_api_rest?platform=All%20Platforms#a-namestatusa响应状态码
5,restful API回调:https://docs.agora.io/cn/cloud-recording/cloud_recording_callback_rest?platform=All%20Platforms
6,文档中的截图仅供参考

1,先创建一个用于录制测试的频道,频道内至少包含一个有效发流的客户端

频道信息可以在水晶球中查看: https://dashboard.agora.io/analytics/call/search
水晶球使用说明:https://docs.agora.io/cn/Agora%20Platform/aa_guide?platform=All%20Platforms
水晶球使用范例:https://docs.agora.io/cn/Agora%20Platform/aa_tutorial?platform=All%20Platforms

2,获取recourseId

使用postman请求

官网文档:https://docs.agora.io/cn/cloud-recording/cloud_recording_api_rest?platform=All%20Platforms#a-nameacquirea获取云端录制资源的-api
特别说明:recourseid必须在五分钟内使用, 否则将返回400错误,返回的sid为空
请求url示例:https://api.agora.io/v1/apps//cloud_recording/acquire

获取您的customerID账户,请参考文档: https://docs.agora.io/cn/cloud-recording/cloud_recording_api_rest?platform=All%20Platforms#a-nameautha认证

curl命令 请求示例

使用curl命令时,一个空格,一个字符都不能错。

$ curl -u <customerID>:<customer certificate> https://api.agora.io/v1/apps/<appid>/cloud_recording/acquire -H "Content-Type:application/json" -d '{"cname":"<频道号>","uid":"<录制uid>","clientRequest":{}}'
返回的resourceID
{"resourceId":"RrCi4XQBEUIoCdZLAWdRJLVK4_3ppnaJGghIoDZuC3HGNOb-x2I8AXJj_2evYwExvSkP_WgZVT6V4GtjzWg8-ky5w9CfmAQIFKNDGWzaaWgTTnxZ-E3eEN-SLMFK46M4SlSYMTLYqTgrYRGUgclOgcdGGmhUEZhEcw0UrGxdrbjHuqdah1wgnqj-AJ2OIzyUuvEJQCB9SBRuAfiazmqCY3SjdRc1Q-ywJZzIG27Ub40"}

请求成功的示例截图

php 请求示例

测试环境:在Mac 上面安装 MAMP 即可

<?php
$url = "https://api.agora.io/v1/apps/<your appid>/cloud_recording/acquire"; 
$arr_header[] = "Content-Type:application/json"; 
$arr_header[] = "Authorization: Basic ".base64_encode("<your customerID>:<your customerCertificate>"); //http basic auth 

$data = array('cname'=>'<cname>','uid'=>'<录制uid>','clientRequest'=>json_decode("{}"));
$data_json = json_encode($data);
echo $data_json;

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url ); //request url
curl_setopt($ch, CURLOPT_POST, 1); //post提交方式
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //print

if(!empty($arr_header)){ 
curl_setopt($ch, CURLOPT_HTTPHEADER, $arr_header); 
} 
$response = curl_exec($ch); 
curl_close($ch);
echo $response; 
return json_decode($response); 
?>

在浏览器执行response
http://localhost:8888/cloudrecordingrequire.php

Java post请求示例(仅供参考)

package io.agora.javaapi;
import java.io.IOException;
import javax.xml.bind.DatatypeConverter;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.ParseException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
public class CloudRecording1 {
public static void main(String[] args) throws ParseException, IOException {
// TODO Auto-generated method stub
HttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost("https://api.agora.io/v1/apps/<appid>/cloud_recording/acquire");

String encoding = DatatypeConverter.printBase64Binary("<customer ID>:<customer certificate>".getBytes("UTF-8"));
String body = "{\n \"cname\":\"<频道号>\",\n \"uid\":\"<录制uid>\",\n \"clientRequest\":{}\n}";

httpPost.setHeader("Content-type", "application/json;charset=utf-8");
httpPost.setHeader("Authorization", "Basic " + encoding);
httpPost.setEntity(new StringEntity(body));

HttpResponse response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
String content = EntityUtils.toString(entity, "utf-8");
System.out.println(content);
System.out.println(httpPost.getURI());
System.out.println(response);
}
}

返回结果

{"resourceId":"RrCi4XQBEUIoCdZLAWdRJLVK4_3ppnaJGghIoDZuC3HGNOb-x2I8AXJj_2evYwEx12wmwz04Ik03j8DKekkisQcKKgHqP2IeFt_NigcILOKdp0320OAX4d-gFHWqWdaP56bhnV-g3tJG-1nQGIjco8pDnAQvPqPYIfbqeq2VHpQloUnpn_TcOyDcEoLTHlVqt6uqq8YOfoMnhX6re-iie2eQyxskhOsyBVIyxdUCPT4"}
https://api.agora.io/v1/apps/<appid>/cloud_recording/acquire
HttpResponseProxy{HTTP/1.1 200 0 [Content-Type: application/json, Content-Length: 253, Connection: keep-alive, X-RateLimit-Limit-second: 10, X-RateLimit-Remaining-second: 9, Accept-Ranges: bytes, Access-Control-Allow-Origin: *, X-Request-ID: 7ed81b0e-a3b6-4251-9628-c46ba37e5db5] ResponseEntityProxy{[Content-Type: application/json,Content-Length: 253,Chunked: false]}}

3,开始录制

特别说明:
集成测试阶段建议使用未开appID认证的app ID, 等跑通之后,再添加token
只使用app ID鉴权时, token传空即可 “token”:""

使用postman 请求

官网文档:https://docs.agora.io/cn/cloud-recording/cloud_recording_api_rest?platform=All%20Platforms#a-namestarta开始云端录制的-api
https://api.agora.io/v1/apps//cloud_recording/resourceid//mode/mix/start

https://api.agora.io/v1/apps/<appid>/cloud_recording/resourceid/<resourceid>/mode/mix/start

{
"uid": "<录制uid>",
"cname": "<频道号>",
"clientRequest": {
"token": "",
"recordingConfig": {
"maxIdleTime": 30,
"streamTypes": 2,
"audioProfile": 1,
"channelType": 0, 
"videoStreamType": 1, 
"transcodingConfig": {
"height": 640, 
"bitrate": 500, 
"fps": 15, 
"mixedVideoLayout": 1,
"maxResolutionUid": "1",
"width": 360
}
}, 
"storageConfig": {
"accessKey": "<accessKey>",
"region": <region>,
"bucket": "<bucket>",
"secretKey": "<secretKey>",
"vendor": <vendor>
}
}
}

获取你的customerID账户,请参考文档: https://docs.agora.io/cn/cloud-recording/cloud_recording_api_rest?platform=All%20Platforms#a-nameautha认证


4,查询录制情况

使用postman请求

官网文档:https://docs.agora.io/cn/cloud-recording/cloud_recording_api_rest?platform=All%20Platforms#a-namequerya查询云端录制状态的-api
https://api.agora.io/v1/apps//cloud_recording/resourceid//sid//mode/mix/query

5,停止录制

使用postman 请求

官网文档:https://docs.agora.io/cn/cloud-recording/cloud_recording_api_rest?platform=All%20Platforms#a-namestopa停止云端录制的-api
https://api.agora.io/v1/apps//cloud_recording/resourceid//sid//mode/mix/stop

6,云平台查看上传情况

使用声网云录制支持的云平台
以七牛云为例
涉及云平台使用问题,请咨询云平台技术方
m3u8文件,生成外链,即可在浏览器播放
官网文档: https://docs.agora.io/cn/cloud-recording/cloud_recording_onlineplay?platform=All%20Platforms 在线播放录制文件

1赞