I am trying to use Google Service Account to list videos from YouTube Data API v3 in .NET. I have activated YouTube API, created Account Service, but whenever I am trying to list videos from my channel, it says 0 videos even if I do have uploaded videos. Could you please help ? Thanks.
Here is the code -
string[] scopes = new string[]
{
YouTubeAnalyticsService.Scope.YtAnalyticsReadonly,
YouTubeAnalyticsService.Scope.YtAnalyticsMonetaryReadonly,
"https://www.googleapis.com/auth/youtube.force-ssl"
};
// service account credential
GoogleCredential credential = GoogleCredential.FromFile(SecretPath).CreateScoped(scopes);
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = channelinfo.AnalyticsAPIFileDataStore
});
Dictionary<string, DateTime?> videoIds = new Dictionary<string, DateTime?>();
var channelResourcesList = youtubeService.Channels.List("contentDetails");
channelResourcesList.Id = channelinfo.ChannelId;
var listResult = channelResourcesList.Execute();
string playListId = listResult.Items[0]?.ContentDetails.RelatedPlaylists.Uploads;
var listOfVideos = youtubeService.PlaylistItems.List("snippet");
listOfVideos.PlaylistId = playListId;
var nextPageToken = "";
while (nextPageToken != null)
{
listOfVideos.MaxResults = 50;
listOfVideos.PageToken = nextPageToken;
// searchresult is empty (listOfVideos.Execute() returns empty result) although channelResourcesList.Execute() worked
var searchListResult = listOfVideos.Execute();
nextPageToken = searchListResult.NextPageToken;
}