|
Below you will Find Code how to use Youtube API using Asp.net (VB.NET).
its a shame all the examples that youtube provided were in c#, and i spent hours finding code/examples in VB.NET but was to no avail. At the end i just used c# version of library that Youtube provided, but my aspx page was in VB.NET.
Here is what i did.
1 - Create Two folders within asp_code directory (vb and cs)
2 - Copy c# version of Youtube Api Example within cs Directory, and keep your other code in vb directory.
3 - in your vb.net aspx page, just reference to your c# class.
Below is a example how to pull all related videos of a certain video.
// Thats in cs directory
public static class ListVideos {
public static IEnumerable<Video> Related(string videoid)
{
Uri videoEntryUrl = new Uri("http://gdata.youtube.com/feeds/api/videos/" + videoid);
YouTubeRequest request = GetRequest();
Video video = request.Retrieve<Video>(videoEntryUrl);
Feed<Video> feed = null;
feed = request.GetRelatedVideos(video);
return feed.Entries;
}
}
And this is how you can call this within aspx page:
<asp:label style="display:none;" runat=server ID="vid"></asp:Label>
<asp:DataList Style="td.vertical-align:top" HorizontalAlign=Center RepeatLayout=Table DataSourceID="SearchYouTubeSourceRelated" runat=server RepeatColumns=5 RepeatDirection=Horizontal ID="sims">
<ItemTemplate>
<a href='/watch.aspx?url=<%#eval("WatchPage") %>'>
<img alt="<%#eval("Title") %>" width=120 src="http://img.youtube.com/vi/<%#Imgurl(Eval("id")) %>/2.jpg" border=0" />
</a><br />
<%#Left(Eval("Title"), 22)%>...
</ItemTemplate>
</asp:DataList>
</p>
<asp:ObjectDataSource ID="SearchYouTubeSourceRelated" runat="server" SelectMethod="Related" TypeName="ListVideos">
<SelectParameters>
<asp:ControlParameter ControlID="vid" DefaultValue="bollywood" Name="videoid" PropertyName="Text"
Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
I hope this will make some sense, if you need other examples such as retrieve comment's, Paging (which never works 100%), search categories, please let me know.
Thanks
- Saqib Khan
|