Hi
I have below code to list my own videos but it is saying No Data Found. In allitems it is showing Count = 0
protected void MyOwnVideos()
{
StringBuilder htmlTable = new StringBuilder();
var client = new RestClient("googleapis.com/youtube/v3");
var request = new RestRequest("search", Method.GET);
request.AddParameter("part", "snippet");
request.AddParameter("type", "video");
request.AddParameter("channelId", "_nNoaVw");
request.AddParameter("key", "AIzaSyFG8");
List allItems = new List();
IRestResponse response = client.Execute(request);
htmlTable.Append("");
htmlTable.Append("Video Id Video Title Description Views Like Comment Published ");
htmlTable.Append("");
foreach (var data in allItems.OrderBy(x => x.snippet.publishedAt))
{
}
Thanks
1 Reply
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Tuhin PaulPosted Feb 9, 2025, 4:21 PM
The issue you're encountering (
Count = 0inallItems) likely stems from one or more of the following problems:https://www.googleapis.com/youtube/v3/search, not justgoogleapis.com/youtube/v3.channelIdyou are using is correct. You can verify it by visiting your YouTube channel and checking the URL or using the API to fetch your channel details.maxResultsparameter is optional but defaults to 5. If you want more results, specify a higher value (e.g.,maxResults=50).Changed the base URL to
https://www.googleapis.com/youtube/v3.Check the
channelIdis correct. You can find it by:Check the API key is valid and has access to the YouTube Data API.
Added a check to ensure the response contains data before proceeding.
Fixed the loop to iterate over
response.Data.itemsinstead of an emptyallItemslist.Added
maxResults=50to fetch up to 50 videos per request.Test your API key with a simple GET request in your browser or Postman
Use the following API endpoint to fetch your channel details and confirm the
channelId:Log the raw response from the API to debug any issues: