Sunday, 21 June 2015

YouTube Comments and Commenting with YouTube API V3 (Google.Apis.YouTube.v3)




Google deprecated V2 of the YouTube API over a year ago, but as of last month, the URLs have been taken offline; forcing users to upgrade to V3 of the API. One of the last features requiring implementating on the V3 platform was the ability to comment on channels and videos. The following example shows how to leave a top level comment on a channel or video using V3 of the API with C#

Example
Code Snippet
  1.  
  2. YouTubeService youtube; // Init your service here - Make sure you include the new required scope: YouTubeService.Scope.YoutubeForceSsl
  3.  
  4. CommentThreadSnippet commentThreadSnippet = new CommentThreadSnippet();
  5. //commentThreadSnippet.ChannelId; Comment on a channel - leave video id blank if so
  6. commentThreadSnippet.VideoId = v.ID; // Comment on a Video by VideoID
  7.  
  8. // A top level comment is a new comment (Not a reply to an existing comment)
  9. commentThreadSnippet.TopLevelComment = new Comment() { Snippet = new CommentSnippet() { TextOriginal = comment }};
  10.  
  11. // Make an insert request and get result snippet
  12. CommentThreadsResource.InsertRequest commentReq = youtube.CommentThreads.Insert(new CommentThread() { Snippet = commentThreadSnippet}, "snippet");
  13. CommentThread commentRes = commentReq.Execute();
End of Code Snippet

3 comments:

Unknown said...

hi mate! can you make full code for youtube comment with API v3?

Queens Technology said...

GREATTT Thanks a lot

Kevin said...

My channel experienced a significant boost in engagement and visibility after using this service.