2009-10-05 11 views
6

YouTube API for .NETを使用してビデオエントリからコメントフィードを取得しようとしています。私はWPFとC#のプログラムに取り組んでいますが、私がこのフィードを取得する方法を理解することはできません。YouTube APIコメントフィード

私はYouTube API Developer's Guideを見てみましたが、コメントフィード(ページの下部にあります)に関する情報が不足しているようです。

答えて

-1
YouTubeRequest request = ... // Your request object  
Video v = ... // Your video object 
Feed<Comment> comments = request.GetComments(v); 

comments.entriesCommentオブジェクトとしてビデオVのためのコメントをすべて含んでいますので、あなたは、すべてのフィードを台無しにする必要はありません。

1

これはYouTube APIのバージョン3で変更されました。 commentThreads/listと呼ばれる新しいエンドポイントがあり、リソースのコメントスレッドを返すことができます。

ビデオリソースのコメントリストを返信する場合は、part=id,snippetvideoId=[VIDEO_ID]というGETリクエストを設定します。私は、一例としてhttps://www.youtube.com/watch?v=HwNIDcwfRLYを使用することがあります:

HTTP GET https://www.googleapis.com/youtube/v3/commentThreads?part=id%2Csnippet&videoId=HwNIDcwfRLY&key={YOUR_API_KEY} 

はさんが最初のコメントを例として返さ使用してみましょう:コメントはこの topLevelCommentオブジェクトでは、実際にはないことを

{ 
    "kind": "youtube#commentThread", 
    "etag": "\"DsOZ7qVJA4mxdTxZeNzis6uE6ck/jhK_kJqnNF8_fiRI_o7w6ehubv8\"", 
    "id": "z120sfshyxzewt1nx23sevyr1vu1jd2pr04", 
    "snippet": { 
     "videoId": "HwNIDcwfRLY", 
     "topLevelComment": { 
      "kind": "youtube#comment", 
      "etag": "\"DsOZ7qVJA4mxdTxZeNzis6uE6ck/h903NemnXx-8Hfe6lRIYCFERSe4\"", 
      "id": "z120sfshyxzewt1nx23sevyr1vu1jd2pr04", 
      "snippet": { 
      "authorDisplayName": "mach-a-chine seahawksgoonie", 
      "authorProfileImageUrl": "https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg?sz=50", 
      "authorChannelUrl": "http://www.youtube.com/channel/UCBmJ0sw7plIZHLvhfz7oo_w", 
      "authorChannelId": { 
       "value": "UCBmJ0sw7plIZHLvhfz7oo_w" 
      }, 
      "videoId": "HwNIDcwfRLY", 
      "textDisplay": "", 
      "authorGoogleplusProfileUrl": "https://plus.google.com/102274783439566633837", 
      "canRate": true, 
      "viewerRating": "none", 
      "likeCount": 0, 
      "publishedAt": "2016-02-05T03:42:35.158Z", 
      "updatedAt": "2016-02-05T03:42:35.158Z" 
      } 
     }, 
     "canReply": true, 
     "totalReplyCount": 0, 
     "isPublic": true 
    } 
} 

注意を。 textDisplayは空の文字列を返します。この文字列はYouTube APIでknown issueです。

HTTP GET https://www.googleapis.com/youtube/v3/commentThreads?part=id%2Csnippet&id=z120sfshyxzewt1nx23sevyr1vu1jd2pr04&key={YOUR_API_KEY} 

結果の応答のsnippet辞書はキーtextDisplayの値として、ユーザーのコメントがあります:私たちは、[COMMENT_ID]topLevelComment.idあるid=[COMMENT_ID]commentThreads/listへの追加要求を、確認する必要があり

"snippet": { 
    "authorDisplayName": "mach-a-chine seahawksgoonie", 
    "authorProfileImageUrl": "https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg?sz=50", 
    "authorChannelUrl": "http://www.youtube.com/channel/UCBmJ0sw7plIZHLvhfz7oo_w", 
    "authorChannelId": { 
      "value": "UCBmJ0sw7plIZHLvhfz7oo_w" 
    }, 
    "videoId": "HwNIDcwfRLY", 
    "textDisplay": "my next ring tone! yeah boy!\ufeff", 
    "authorGoogleplusProfileUrl": "https://plus.google.com/102274783439566633837", 
    "canRate": true, 
    "viewerRating": "none", 
    "likeCount": 0, 
    "publishedAt": "2016-02-05T03:42:35.158Z", 
    "updatedAt": "2016-02-05T03:42:35.158Z" 
    } 
} 

コメントは: "私の次の着信音!ええと男の子!"

コメントオブジェクトの文字列を最大でカンマ区切りのidまたはvideoId個のリストに渡して、API呼び出しごとに取得することもできます。

追加情報とサンプルコードについては、Retrieve comments for a videoガイドを参照してください。