Reputation: 41
I am trying to get youtube video information for each video in my youtube playlist. That way I can hook my PowerBI dashbaords and other email tool to a SQL database with all my youtube video meta data in it. I have a method that will grab all of the Snippet video information. But it fails when grabbing the other parts.This link clearly shows that content details is a valid operation but the APIgives me a 400 back. I have to be really close. Any ideas?
https://developers.google.com/youtube/v3/docs/videos/list#parameters
public YouTubeVideo GetVideoInfo(string id)
{
var videoRequest = ytservice.Videos.List("snippet");
var contentRequest = ytservice.Videos.List("contentdetials");
var itemRequest = ytservice.Videos.List("items");
var statsRequest = ytservice.Videos.List("Statistics");
videoRequest.Id = id;
contentRequest.Id = id;
itemRequest.Id = id;
statsRequest.Id = id;
var response = videoRequest.Execute();
var contentResponse = contentRequest.Execute();
var itemResponse = itemRequest.Execute();
var statsResponse = statsRequest.Execute();
var video = new YouTubeVideo();
if (response.Items.Count > 0)
{
video.id = videoRequest.Id;
video.caption = contentResponse.Items[0].ContentDetails.Caption;
video.title = response.Items[0].Snippet.Title;
video.description = response.Items[0].Snippet.Description;
video.publishDate = response.Items[0].Snippet.PublishedAt.Value;
video.ageGate = itemResponse.Items[0].AgeGating.Restricted;
video.viewCount = response.Items[0].Statistics.ViewCount;
video.likeCount = statsResponse.Items[0].Statistics.LikeCount;
video.dislikeCount = statsResponse.Items[0].Statistics.DislikeCount;
video.favoriteCount = statsResponse.Items[0].Statistics.FavoriteCount;
video.commentCount = statsResponse.Items[0].Statistics.CommentCount;
}
else
{
//Video not found
}
return video;
}
Upvotes: 2
Views: 1268
Reputation: 41
I figured out i could make all of the calls in the same string just seperated by commas :)
public YouTubeVideo GetVideoInfo(string id)
{
var videoRequest = ytservice.Videos.List("snippet, contentDetails, statistics");
videoRequest.Id = id;
var response = videoRequest.Execute();
var video = new YouTubeVideo();
if (response.Items.Count > 0)
{
video.id = videoRequest.Id;
video.caption = response.Items[0].ContentDetails.Caption;
video.title = response.Items[0].Snippet.Title;
video.description = response.Items[0].Snippet.Description;
video.publishDate = response.Items[0].Snippet.PublishedAt.Value;
//video.ageGate = (response.Items[0].AgeGating.Restricted = null) ? null : response.Items[0].AgeGating.Restricted;
video.viewCount = response.Items[0].Statistics.ViewCount;
video.likeCount = response.Items[0].Statistics.LikeCount;
video.dislikeCount = response.Items[0].Statistics.DislikeCount;
video.favoriteCount = response.Items[0].Statistics.FavoriteCount;
video.commentCount = response.Items[0].Statistics.CommentCount;
}
else
{
//Video not found
}
return video;
}
Upvotes: 2