2016-08-08 17 views
1

私は、許可C#で入れて、ビデオにタイトルを更新しようとしています:YouTube APIとC#でエラー400が発生しましたか?

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); 
} 

上記のコードは次のエラーを示しています。

The remote server returned an error: (400) Bad Request.

は私が間違って何をやっているの?

+0

現在の形式の代わりに 'snippet.title'と' snippet.categoryId'を試しましたか?私が見ることのできるところからは、JSONのビデオオブジェクトをそのままボディとして渡す必要がありますが、エンコードされたデータもエンコードされている可能性があります。P – starlight54

答えて

0

私はそれを理解しました。この特定のエンドポイントは、応答x-www-form-urlencodedの代わりにjson応答を必要とします。

関連する問題