Hi
I have below code . I want Category wise most viewed youtube videos
using (var yt = new YouTubeService(new BaseClientService.Initializer()
{
ApiKey = "AIzaSyKu9f5blF7idak6cGul59UQ7c7Ls8ECKT8",
}))
{
StringBuilder htmlTable = new StringBuilder();
var request = yt.Search.List("snippet");
request.Order = Google.Apis.YouTube.v3.SearchResource.ListRequest.OrderEnum.ViewCount;
request.PublishedAfter = DateTime.Today;
request.PublishedBefore = DateTime.Today.AddDays(1);
var response = request.Execute();
var objResult = response.Items.ToList();
Thanks
Naimish MakwanaPosted Jan 31, 2023, 3:34 PM
Hello Ramco,
use below code. Its working fine and tested.
need to use small "v" instead of Capital "V".
Working code.
Please mark answer accepted if its useful.
Thanks
Naimish
Ramco RamcoPosted Jan 31, 2023, 3:17 PM
Hi Naimish
Then it gives below error
It is giving below error - Google.GoogleApiExceptiond__35.MoveNext()
HResult=0x80131500
Message=The service youtube has thrown an exception. HttpStatusCode is BadRequest. Request contains an invalid argument.
Source=Google.Apis
StackTrace:
at Google.Apis.Requests.ClientServiceRequest`1.
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Google.Apis.Requests.ClientServiceRequest`1.Execute()
at MyChannel.Admin.MyVideos.MostViewdVideos() in E:\MyChannel\MyChannel\Admin\MyVideos.aspx.cs:line 52
at MyChannel.Admin.MyVideos.Page_Load(Object sender, EventArgs e) in
Thanks
Naimish MakwanaPosted Jan 31, 2023, 3:02 PM
Error is due to you are assing int to string type.
try this.
request.VideoCategoryId = "10";
Ramco RamcoPosted Jan 31, 2023, 2:55 PM
Hi Sachin
It is giving error Cannot implicitly convert type int to string on second line
request.Type = "Video";
request.VideoCategoryId = 10;
Thanks
Ramco RamcoPosted Jan 31, 2023, 2:32 PM
Hi
It is giving same error on - request.VideoCategoryId = "10";
Thanks
Naimish MakwanaPosted Jan 31, 2023, 2:16 PM
Try below code.
Thanks
Ramco RamcoPosted Jan 31, 2023, 12:31 PM
Hi Sachin
It is giving below error on below line;
request.VideoCategoryId = "10";
It is giving below error - Google.GoogleApiExceptiond__35.MoveNext()
HResult=0x80131500
Message=The service youtube has thrown an exception. HttpStatusCode is BadRequest. Request contains an invalid argument.
Source=Google.Apis
StackTrace:
at Google.Apis.Requests.ClientServiceRequest`1.
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Google.Apis.Requests.ClientServiceRequest`1.Execute()
at MyChannel.Admin.MyVideos.MostViewdVideos() in E:\MyChannel\MyChannel\Admin\MyVideos.aspx.cs:line 52
at MyChannel.Admin.MyVideos.Page_Load(Object sender, EventArgs e) in
Sachin SinghPosted Jan 31, 2023, 11:46 AM
you can use VideoCategoryId