idays021 2020-03-21 17:04 采纳率: 0%
浏览 2632
已结题

抖音开放平台的上传视频到文件服务器(/video/upload/)API为什么总是返参数不合法回?

API文档地址:
https://open.douyin.com/platform/doc/OpenAPI-video-create

调用接口:

图片说明

接口参数:
图片说明

平台已申请的权限:

图片说明

问题描述:

在调用 https://open.douyin.com/video/upload/接口是总数返回参数不合法,用该接口调用时所使用的open_id和access_token调用其他接口(如:/video/list/)都可返回调用成功数据,可以肯定的是,open_id和access_token参数没有问题,接口权限 (Scope: “video.create”)在开放平台已经申请并审核通过,在扫码授权时,也已经传如了Scope权限。

调用API返回结果如下:

{"data":{"description":"参数不合法","error_code":2100005},"extra":{"logid":"202003211443340100140470891DF1B821","now":1584773018222}}

注:接口测试采用多种测试方式都是这个结果:

所采用的测试方式有:

1)C# 程序调用

2)jquery前端直接调用

3) postman调用

C# 实现代码:

var userInfo = _sessionHelper.GetSession();
                var url = "https://open.douyin.com/video/upload";
                string filePath = @"D:/dy3.mp4";

                Dictionary<string, string> dicData = new Dictionary<string, string>();
                dicData.Add("open_id", userInfo.data.open_id);
                dicData.Add("access_token", userInfo.data.access_token);

                Dictionary<string, string> dicFiles = new Dictionary<string, string>();
                dicFiles.Add("video", "D:/dy3.mp4");
                var res = Util.PostHttpResponse(url, dicData, dicFiles);

PostHttpResponse方法:

public static string PostHttpResponse(string url, Dictionary<string, string> postData, Dictionary<string, string> files)
        {
            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
            CookieContainer cookieContainer = new CookieContainer();
            request.CookieContainer = cookieContainer;
            request.AllowAutoRedirect = true;
            request.Method = "POST";
            string boundary = DateTime.Now.Ticks.ToString("X"); // 随机分隔线
            request.ContentType = "multipart/form-data;charset=utf-8;boundary=" + boundary;

            byte[] itemBoundaryBytes = Encoding.UTF8.GetBytes("\r\n--" + boundary + "\r\n");
            byte[] endBoundaryBytes = Encoding.UTF8.GetBytes("\r\n--" + boundary + "--\r\n");

            Stream postStream = request.GetRequestStream();
            postStream.Write(itemBoundaryBytes, 0, itemBoundaryBytes.Length);

            //写入文本
            if (postData != null && postData.Count > 0)
            {
                var keys = postData.Keys;
                foreach (var key in keys)
                {
                    string strHeader = string.Format("Content-Disposition: form-data; name=\"{0}\"\r\n\r\n", key);
                    byte[] strByte = System.Text.Encoding.UTF8.GetBytes(strHeader);
                    postStream.Write(strByte, 0, strByte.Length);

                    byte[] value = System.Text.Encoding.UTF8.GetBytes(string.Format("{0}", postData[key]));
                    postStream.Write(value, 0, value.Length);

                    postStream.Write(itemBoundaryBytes, 0, itemBoundaryBytes.Length);

                }
            }
            postStream.Write(itemBoundaryBytes, 0, itemBoundaryBytes.Length);

            //写入文件
            if (files != null && files.Count > 0)
            {
                var keys = files.Keys;

                foreach (var key in keys)
                {
                    string filePath = files[key];
                    int pos = filePath.LastIndexOf("\\");
                    string fileName = filePath.Substring(pos + 1);
                    StringBuilder sbHeader = new StringBuilder(string.Format("Content-Disposition:form-data;name=\"{0}\";filename=\"{1}\"\r\nContent-Type:application/octet-stream\r\n\r\n", key, fileName));
                    byte[] postHeaderBytes = Encoding.UTF8.GetBytes(sbHeader.ToString());

                    FileStream fs = new FileStream(files[key], FileMode.Open, FileAccess.Read);
                    byte[] bArr = new byte[fs.Length];
                    fs.Read(bArr, 0, bArr.Length);
                    fs.Close();
                    postStream.Write(postHeaderBytes, 0, postHeaderBytes.Length);
                    postStream.Write(bArr, 0, bArr.Length);

                    postStream.Write(itemBoundaryBytes, 0, itemBoundaryBytes.Length);
                }

            }
            postStream.Write(endBoundaryBytes, 0, endBoundaryBytes.Length); //结束标志
            postStream.Close();
            //发送请求并获取相应回应数据
            HttpWebResponse response = request.GetResponse() as HttpWebResponse;
            //直到request.GetResponse()程序才开始向目标网页发送Post请求
            Stream instream = response.GetResponseStream();
            StreamReader sr = new StreamReader(instream, Encoding.UTF8);
            //返回结果网页(html)代码
            string content = sr.ReadToEnd();
            return content;
        }
  • 写回答

1条回答 默认 最新

  • threenewbee 2020-03-21 21:41
    关注

    这里要求你使用 multipart/form-data 传 json
    你是不是不是multipart/form-data,也就是类似 base64 那种带有分段的,以及传入的内容不是json
    检查下

    评论

报告相同问题?

悬赏问题

  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?