文档中心 Cloud VoD API (OId Version) Example: Include Authentication in Request

Example: Include Authentication in Request

更新时间:2023-02-08 10:00:19

目录

示例一:通过鉴权发送请求获取云点播视频列表V3 (Java)

在使用代码之前,您应该将until.jar导入到您的项目中。

import com.cnc.cloudv.util.auth.ApiAuthUtil;
import com.cnc.cloudv.util.httpclient.CloudvHttpResponse;

import java.util.HashMap;
import java.util.Map;

public class TestAuthUtil {
    private final static String ACCESS_KEY = "Your AccessKey";
    private final static String SECRET_KEY = "Your AccessKey Secret";
    // API_HOST is Cloud VoD API domain
    private final static String API_HOST = "api.cloudv.haplat.net";

    public static void main(String[] args) throws Exception {
        Map<String, String> customHeaderMap = new HashMap<String, String>(2);
	// below is a customized header
        customHeaderMap.put("from", "test-authentification-sdk");
	// URI of the request
        String requestURI = "/vod/videoManage/getVideoList";

	// POST request example
        String body = "{\"videoName\": \"test\",\"pageIndex\":\"2\",\"pageSize\":\"5\",\"format\": \"json\"}";
        CloudvHttpResponse cloudvHttpResponse = ApiAuthUtil.callPostJsonBodyRequest(API_HOST, ACCESS_KEY, SECRET_KEY, requestURI, customHeaderMap, body);
        log(cloudvHttpResponse);
		
	// GET request example
        String canonicalQueryString = "videoName=" + java.net.URLEncoder.encode("test", "utf-8") + "&pageIndex=2&pageSize=5&format=json";
        cloudvHttpResponse = ApiAuthUtil.callGetRequest(API_HOST, ACCESS_KEY, SECRET_KEY, requestURI, customHeaderMap, canonicalQueryString);
        log(cloudvHttpResponse);

	// Form-Urlencoded POST request example
        body = "videoName=" + java.net.URLEncoder.encode("test", "utf-8") + "&pageIndex=2&pageSize=5&format=json";
        cloudvHttpResponse = ApiAuthUtil.callPostFormUrlencodedBodyRequest(API_HOST, ACCESS_KEY, SECRET_KEY, requestURI, customHeaderMap, body);
        log(cloudvHttpResponse);
		
		
	// Map POST request example
        Map<String, String> map = new HashMap<String, String>();
        map.put("videoName", "test");
        map.put("pageIndex", "2");
        map.put("pageSize", "5");
        map.put("format", "json");
        cloudvHttpResponse = ApiAuthUtil.callPostFormUrlencodedBodyRequest(API_HOST, ACCESS_KEY, SECRET_KEY, requestURI, customHeaderMap, map);
        log(cloudvHttpResponse);

        System.out.print("Request ends");

    }

    public static void log(CloudvHttpResponse cloudvHttpResponse) throws Exception {
	// Print out the X-WS-RequestId for a further troubleshooting
        System.out.println("Response:" + cloudvHttpResponse + " , requestId = " + cloudvHttpResponse.getHeaders().get("X-WS-RequestId"));
    }

}

示例二:获取 Upload Token 然后在 Postman 中上传

下面我们举例说明如何在 Postman 中通过发送请求来上传视频。您可以下载Postman 脚本并导入到您的 Postman 工具中,以轻松发送请求并将您的视频上传到 Cloud VoD。
有两个步骤:

  1. 获取上传令牌。
  2. 上传视频。

获取上传令牌

首先将脚本导入您的 Postman。将secretKey和accessKey改成自己的AccessKey Secret和AccessKey ID。
Self-Service Configuration for China Premium Service Onboarding
将 orginFileName 更改为您自己要上传的视频的名称。然后发送请求。
Self-Service Configuration for China Premium Service Onboarding
复制并保存 uploadUrl 和 uploadToken 以便在视频上传中进一步使用。
Self-Service Configuration for China Premium Service Onboarding

上传视频

有了上传令牌和 URL,现在您可以上传视频了。进入API正常上传,请按照以下步骤操作:

  1. 将域更改为您从获取上传令牌 API 获得的 uploadUrl。
  2. 选择您要上传的文件。
  3. 填写您从 Get Upload Token API 获取的令牌。
    Self-Service Configuration for China Premium Service Onboarding
本篇文档内容对您是否有帮助?
有帮助
我要反馈
提交成功!非常感谢您的反馈,我们会继续努力做到更好!