Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
YouTube API和C#出现错误400?_C#_Youtube - Fatal编程技术网

YouTube API和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视频对象作为主体,但它们也可能采用格式

我正在尝试用C#中的授权输入将标题更新为视频:

上述代码显示以下错误:

远程服务器返回错误:(400)请求错误


我做错了什么?

我知道了。这个特定的端点需要一个
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);
}