【问题标题】:Error 400 with YouTube API and C#?YouTube API 和 C# 出现错误 400?
【发布时间】:2016-08-08 23:44:30
【问题描述】:

我正在尝试将标题更新为视频,并在 C# 中获得授权:

string postUrl = "https://www.googleapis.com/youtube/v3/videos?part=snippet&access_token=" + this.access_token;
string postData = "id=" + this.videoID +
    "&snippet[title]=" + Uri.EscapeDataString(status.Text) +
    "&snippet[categoryId]=20";
byte[] postByte = Encoding.UTF8.GetBytes(postData);

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(postUrl);

request.Method = "PUT";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postByte.Length;
request.Timeout = 15000;

try
{
    Stream putStream = request.GetRequestStream();
    putStream.Write(postByte, 0, postByte.Length);
    putStream.Close();

    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
}
catch (WebException err)
{
    MessageBox.Show(err.Message);
}

以上代码显示如下错误:

远程服务器返回错误:(400) Bad Request。

我做错了什么?

【问题讨论】:

  • 您是否尝试过snippet.titlesnippet.categoryId 而不是当前的格式?从我所见,无论如何您都必须将完整的 JSON 视频对象作为主体,但它们也可能采用编码数据的形式,我只是看不到它:P

标签: c# youtube


【解决方案1】:

我想通了。此特定端点需要json 响应,而不是x-www-form-urlencoded 响应。

【讨论】:

    猜你喜欢
    • 2011-09-11
    • 2011-06-18
    • 2015-11-04
    • 2018-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-09
    • 1970-01-01
    相关资源
    最近更新 更多