0

YouTube と対話する VB.NET でデスクトップ アプリケーションを作成しています。これまでのところ、OAuth2 認証の「問題」を解決することができ、トークン (認証と更新) を持っています。認証トークンを 1 時間ごとに更新する必要がありますが、これは問題ではありません。

http POST と YouTube API を使用して、さまざまな方法で動画にコメントを投稿しようとしました。HTTP リクエストの POST で「不正なリクエスト」の応答が返され、YouTube API の試行で何も取得されず、コメントも投稿されず、エラーも発生しません。これどうやってするの?YouTube Data API のドキュメントが壊れていて、開くことも Visual Studio にインストールすることもできないため、人々がオンラインに投稿した小さな例を使用して試行錯誤しながらテストを行っています。

これは、HTTP バージョンに使用したコードです。

'create the xml comment as in API example
Dim ContentLenght As Long
Dim xmlData As New System.Xml.XmlDocument()
Dim commentXML As XDocument =
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom"
    xmlns:yt="http://gdata.youtube.com/schemas/2007">
<content><%= comment %></content>
</entry>

ContentLenght = commentXML.ToString.Length

'---------------------------------------------------------
'create the POST request to submit the comment

Dim sentXml As Byte() = System.Text.Encoding.ASCII.GetBytes(commentXML.ToString)
Dim url = "http://gdata.youtube.com/feeds/api/videos/" & videoID & "/comments"
Dim req As New WebClient
req.Headers.Add("Host: gdata.youtube.com")
req.Headers.Add("Length:" & ContentLenght)
req.Headers.Add("Content-Type: application/atom+Xml")
req.Headers.Add("Authorization: Bearer " & Token)
req.Headers.Add("GData-Version: 2")
req.Headers.Add("X-GData-Key: key=" & developerKey)
Dim response As Byte() = req.UploadData(url, "POST", sentXml)

私が試したAPIコードは次のとおりです。

Dim commentingSettings As New YouTubeRequestSettings(appName, developerKey, Token)
Dim lcommentingRequest As New YouTubeRequest(commentingSettings)

Dim video As New Video()
video.VideoId = "JEvV0RHMU-Y"
Dim comm As New Comment
comm.Content = "comm text here"

lcommentingRequest.AddComment(video, comm)
4

2 に答える 2

0

現在、YouTube API v3 はコメントをサポートしていません。v2 のみがサポートされます。将来あるかもしれないことを願っています。

于 2013-07-15T02:11:45.747 に答える