Frederik Vig – ASP.NET developer

Follow me

SlideShare .NET API Wrapper

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.

From SlideShare

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.

Download the code

Related Posts:

Share:
  • Twitter
  • DotNetKicks
  • DZone
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • StumbleUpon
  • Digg

3 Comments

  1. [...] previous posts I’ve blogged about the SlideShare API. In this post I’m going to show how you can use it to create a Dynamic Content Plugin that [...]

  2. Unni says:

    Hi,

    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

  3. backlinks says:

    Really great informative blog post here and I just wanted to comment & thank you for posting this. I’ve bookmarked youi blog and I’ll be back to read more in the future my friend! Also nice colors on the layout, it’s really easy on the eyes.

Leave a Reply

Spam Protection by WP-SpamFree

© Copyright Frederik Vig. Based on Fluid Blue theme