YouTube API和C#出现错误400?
我正在尝试用C#中的授权输入将标题更新为视频: 上述代码显示以下错误: 远程服务器返回错误:(400)请求错误YouTube API和C#出现错误400?,c#,youtube,C#,Youtube,我正在尝试用C#中的授权输入将标题更新为视频: 上述代码显示以下错误: 远程服务器返回错误:(400)请求错误 我做错了什么?我知道了。这个特定的端点需要一个json响应,而不是x-www-form-urlencoded响应。我找到了答案。此特定端点需要json响应,而不是x-www-form-urlencoded响应。您是否尝试过snippet.title和snippet.categoryId而不是当前格式?从我看到的情况来看,您必须提供一个完整的JSON视频对象作为主体,但它们也可能采用格式
我做错了什么?我知道了。这个特定的端点需要一个
json
响应,而不是x-www-form-urlencoded
响应。我找到了答案。此特定端点需要json
响应,而不是x-www-form-urlencoded
响应。您是否尝试过snippet.title
和snippet.categoryId
而不是当前格式?从我看到的情况来看,您必须提供一个完整的JSON视频对象作为主体,但它们也可能采用格式编码数据,我就是看不到:您是否尝试了snippet.title
和snippet.categoryId
而不是当前格式?从我看到的情况来看,你必须给出一个完整的JSON视频对象作为主体,但它们也可能采用形式编码数据,我就是看不到:P
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);
}