YouTube API和C#错误400?

时间:2016-08-08 23:44:30

标签: c# youtube

我正在尝试将标题更新为视频,并在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)错误请求。

我做错了什么?

1 个答案:

答案 0 :(得分:0)

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