Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post May 08, 2012 11:24 AM by ajishvrnair
Member
224 Points
122 Posts
Mar 22, 2012 10:38 AM|LINK
Dear All,
In my MVC3 project i want a youtube search screen with video name.
I already done it through google API. But my problem is, i want to show the duration of video, description as a search result.
Unfortunatly the result i got from google API doesn't contains it.
I already check the youtube API documentaion and there it mention clearly that the result contains duration and description.
https://developers.google.com/youtube/2.0/developers_guide_protocol_understanding_video_feeds#Understanding_Video_Entries
But I didn't get these values.
From the document i know that it is API V2.0 BUT my version is 1.9.0.0 .
Is this the real issue ?? if so from where i can download the version 2.0 ?
I also give the code that i used.
List<YoutubeVideoDetails> videoHolder = new List<YoutubeVideoDetails>(); FeedQuery youtubeQuery = new FeedQuery(""); Service youtubeService = new Service("youtube", "Media Folder"); string url = "http://gdata.youtube.com/feeds/videos?q=" + searchKey + "&orderby=viewCount"; youtubeQuery.Uri = new Uri(url); youtubeQuery.StartIndex = 0; youtubeQuery.NumberToRetrieve = 50; AtomFeed itemFeed = youtubeService.Query(youtubeQuery); if (itemFeed.NextChunk != null) { // Get AtomFeed from YouTube List<AtomEntry> objatomEntry = itemFeed.Entries.ToList(); for (int i = 0; i < objatomEntry.Count; i++) { YoutubeVideoDetails objVideoDetails = new YoutubeVideoDetails(); string youtubeUrl = objatomEntry[i].AlternateUri.Content; long time = (objatomEntry[i].Published.Ticks); TimeSpan ts = TimeSpan.FromTicks(time); double minutesFromTs = ts.TotalMinutes; objVideoDetails.videoId = youtubeUrl.Split('&')[0].Substring(youtubeUrl.Split('&')[0].LastIndexOf("=") + 1).ToString(); objVideoDetails.date = objatomEntry[i].Published.Date.ToString("dd-MMM-yyyy"); objVideoDetails.videoName = objatomEntry[i].Title.Text; videoHolder.Add(objVideoDetails); } }
Thanks
Ajeesh
All-Star
24675 Points
4250 Posts
Mar 22, 2012 11:41 AM|LINK
You should post this question to a Google API forum or something like that. There is no MVC3 issue in here.
May 08, 2012 11:24 AM|LINK
The issue is resolved now.
The problem is with Atom Feed. Actuall last time i am using Atom Feed , but it contains limited no of response.
By using Feed<Video> i got all response from youtube as per the documentaion.
The following code gives the exact youtube search result.
Feed<Video> feed = null; feed = req.Get<Video>(query);
ajishvrnair
Member
224 Points
122 Posts
Youtube video details using gogle API
Mar 22, 2012 10:38 AM|LINK
Dear All,
In my MVC3 project i want a youtube search screen with video name.
I already done it through google API. But my problem is, i want to show the duration of video, description as a search result.
Unfortunatly the result i got from google API doesn't contains it.
I already check the youtube API documentaion and there it mention clearly that the result contains duration and description.
https://developers.google.com/youtube/2.0/developers_guide_protocol_understanding_video_feeds#Understanding_Video_Entries
But I didn't get these values.
From the document i know that it is API V2.0 BUT my version is 1.9.0.0 .
Is this the real issue ?? if so from where i can download the version 2.0 ?
I also give the code that i used.
List<YoutubeVideoDetails> videoHolder = new List<YoutubeVideoDetails>();
FeedQuery youtubeQuery = new FeedQuery("");
Service youtubeService = new Service("youtube", "Media Folder");
string url = "http://gdata.youtube.com/feeds/videos?q=" + searchKey + "&orderby=viewCount";
youtubeQuery.Uri = new Uri(url);
youtubeQuery.StartIndex = 0;
youtubeQuery.NumberToRetrieve = 50;
AtomFeed itemFeed = youtubeService.Query(youtubeQuery);
if (itemFeed.NextChunk != null)
{
// Get AtomFeed from YouTube
List<AtomEntry> objatomEntry = itemFeed.Entries.ToList();
for (int i = 0; i < objatomEntry.Count; i++)
{
YoutubeVideoDetails objVideoDetails = new YoutubeVideoDetails();
string youtubeUrl = objatomEntry[i].AlternateUri.Content;
long time = (objatomEntry[i].Published.Ticks);
TimeSpan ts = TimeSpan.FromTicks(time);
double minutesFromTs = ts.TotalMinutes;
objVideoDetails.videoId = youtubeUrl.Split('&')[0].Substring(youtubeUrl.Split('&')[0].LastIndexOf("=") + 1).ToString();
objVideoDetails.date = objatomEntry[i].Published.Date.ToString("dd-MMM-yyyy");
objVideoDetails.videoName = objatomEntry[i].Title.Text;
videoHolder.Add(objVideoDetails);
}
}
Thanks
Ajeesh
Ajeesh Nair
NB: Please "Mark As Answer", if this helps you
raduenuca
All-Star
24675 Points
4250 Posts
Re: Youtube video details using gogle API
Mar 22, 2012 11:41 AM|LINK
You should post this question to a Google API forum or something like that. There is no MVC3 issue in here.
Radu Enuca | Blog
ajishvrnair
Member
224 Points
122 Posts
Re: Youtube video details using gogle API
May 08, 2012 11:24 AM|LINK
The issue is resolved now.
The problem is with Atom Feed. Actuall last time i am using Atom Feed , but it contains limited no of response.
By using Feed<Video> i got all response from youtube as per the documentaion.
The following code gives the exact youtube search result.
Feed<Video> feed = null;
feed = req.Get<Video>(query);
Ajeesh
Ajeesh Nair
NB: Please "Mark As Answer", if this helps you