SlideShare .NET API Wrapper
Posted on October 18, 2009 by Frederik Vig in .NET, C#In a recent project I had to work with the SlideShare API. Thankfully there was some good documentation to get me started, and even a .NET wrapper for the first version of the API.
SlideShare is a business media site for sharing presentations, documents and pdfs.
After downloading and playing around with the code I decided to upgrade it to version 2 of the API. I encourage you to take a look at the documentation if you haven’t, to see what’s new in version 2 of the API, and what’s available.
SlideShare API Wrapper Methods
Here are the methods that I’ve exposed and made available for you to use. Big thanks to Brian Grinstead for his blog post Multipart Form Post in C# and for Gaurav Gupta for creating the wrapper class for the first version, which this code is based on.
- GetSlideshow
- GetSlideshowsForTag
- GetSlideshowsForGroup
- GetSlideshowsForUser
- SlideshowSearch
- GetUserGroups
- GetUserContacts
- GetUserTags
- EditSlideshow
- DeleteSlideshow
- UploadSlideshow
To use it simply download the code (see link at the bottom of this post), copy the SlideShareAPI.dll into your bin folder and make a reference to it in your project. After you’ve done that you’ll be able to create an instance of the SlideShare class which will expose the methods above.
Remember that you also need an API Key and Shared Secret. Go to the Apply for API Keys page and fill out the form. You should then receive an email with both keys.
Example
Lets get some slideshows that are tagged with web, bind them to a Repeater control and display them to the user.
using System; using System.Linq; using System.Xml.Linq; using SlideShareAPI; namespace FV.Templates.FV.Pages { public partial class SlideShareTest : System.Web.UI.Page { protected override void OnLoad(EventArgs e) { base.OnLoad(e); var slideShare = new SlideShare("API Key", "Shared secret"); var xml = XElement.Parse(slideShare.GetSlideshowsForTag("web", 0, 10)); var slideshows = from slideshare in xml.Elements("Slideshow") select new { Title = slideshare.Element("Title").Value, Description = slideshare.Element("Description").Value, EmbedCode = slideshare.Element("Embed").Value }; rptSlideshows.DataSource = slideshows; rptSlideshows.DataBind(); } } } |
I use Linq to XML and create anonymous objects that I then databind to my Repeater.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SlideShareTest.aspx.cs" Inherits="FV.Templates.FV.Pages.SlideShareTest" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <asp:Repeater runat="server" ID="rptSlideshows"> <HeaderTemplate><ul></HeaderTemplate> <ItemTemplate> <li> <h3><%# HttpUtility.HtmlEncode(Eval("Title").ToString()) %></h3> <p><%# HttpUtility.HtmlEncode(Eval("Description").ToString()) %></p> <%# HttpUtility.HtmlDecode(Eval("EmbedCode").ToString())%> </li> </ItemTemplate> <FooterTemplate></ul></FooterTemplate> </asp:Repeater> </form> </body> </html> |
Most of the code is commented and available through Visual Studio Intellisense. You can also go through and change the code to your needs.
Unni says:
Post Author March 23, 2010 at 08:08Hi,
I have to implement SlideShare API in my application. I have done it but while calling to method name “GetSlideshowsForTag” i am getting response in “es” language (Spanish) but i want in english “en”.
How can i achieve in my application?
Cheers
Unni
sumit gupta says:
Post Author December 15, 2010 at 10:03Hi,
I want to know how to use the this SlideShareAPI after downloading it from the Slideshare site
Vaibhav Pakhare says:
Post Author August 7, 2013 at 15:49Dear Frederik,
I am new to Slideshare .Net wrapper and have tried to implement your API wrapper using my API key and Secret. I am receiving “The remote server returned an error: (404) Not Found.”; whereas I am able to retrieve output using API explorer. I am receiving no other inner exception details other than this error. Please help me in resolving it.
Thanks a lot in advance!