Introducing Spring Social Slideshare

Engineering | Josh Long | February 03, 2015 | ...

This post is a guest post by community member Tadaya Tsuyukubo (@ttddyy), creator of the Spring Social Slideshare project. Thanks Tadaya! I'd like to see more of these guest posts, so - as usual - don't hesitate to ping me! -Josh


Spring Social Slideshare is one of the community modules in Spring Social ecosystem. It is a Java binding built on top of the Spring Social framework to interact with the SlideShare REST API.

Spring Social modules provide an implementation of the ApiBinding interface that binds Java interfaces and concrete implementation classes to a REST API. By convention, an interface is named as target service, e.g. GitHub, LinkedIn, Facebook, etc. The implementation class is of the form *Template, e.g.: GitHubTemplate, LinkedInTemplate, and FacebookTemplate. In Spring Social Slideshare, there is a Slideshare interface and SlideshareTemplate implementation class. You can use spring to inject the SlideshareTemplate to your service. Or, if you choose to, you can directly instantiate SlideshareTemplate and interact with SlideShare API outside of DI from spring.

Creating a SlideShare instance

You need to apply for a SlideShare API key. Once you submit the application form, you will get an email containing “API Key” and “Shared Secret”. You need these two keys to access SlideShare API.

This is the core part of the module to interact with SlideShare API.

SlideShare slideshare = new SlideShareTemplate("api_key", "shared_secret");
SlideshowOperations slideshow = slideshare.slideshowOperations();

Now you can perform slideshow related operation via slideshow instance.

Retrieving a specific Slideshow

Specific slideshow can be retrieved by slideshow id or url.

// get a slideshow "Booting up Spring Social"
Slideshow show = slideshow.getSlideshowById("41084028");

// By url
Slideshow show =  slideshow.getSlideshowByUrl(
  "http://www.slideshare.net/SpringCentral/booting-up-spring-social");

There are many different properties that you can consume including the slideshow's id, url, title, description, created, username, and downloadUrl. If you want to embed the presentation in HTML, use the embed property.

Also, you can retrieve slideshows by user, tag, or group.

GetSlideshowsResponse response;

// by user
response = slideshow.getSlideshowsByUser(
  "SpringCentral", FETCH_SIZE);

// you can also specify offset and detailed flag
response = slideshow.getSlideshowsByUser("SpringCentral",
  FETCH_SIZE, offset, true);

// by tag or group
response = slideshow.getSlideshowsByTag("spring", FETCH_SIZE);
response = slideshow.getSlideshowsByGroup("group_name", FETCH_SIZE);

// You can print the `count` and `name`
List<Slideshow> shows = response.getSlideshows();    // list of slideshows

Performing Searches

You can search slideshows by keyword:

SearchSlideshowsResponse response;
response = slideshow.searchSlideshows("spring");

// paginated access
int page = 3;
int itemsPerPage = 20;
response = slideshow.searchSlideshows("spring", page, itemsPerPage);

List<Slideshow> shows = response.getSlideshows();

Each response has a numResults and totalResults property that gives you the number of results returned and the total results of the result collection.

Creating and Uploading Presentations

You can upload a presentation by specifying a java.io.File, String, and an implementation of Spring's Resource hierarchy.

Note: SlideShare API requires extra permission for upload operation. Please see “SlideShare API Documentation” for requesting upload permission on your dev account.


File file = new File( "path_to_your_presentation_file");
String uploadedShowId = slideshow.uploadSlideshowFromFile(
  username, password, file, "My Title", "My Description");

// Other API to upload slideshows
//   slideshow.uploadSlideshowResource(...)
//   slideshow.uploadSlideshowFromContent(...)
//   slideshow.uploadSlideshowFromUrl(...)

You can modify your slideshow's information, as well.


List<String> tags = Arrays.asList("spring", "social");
PrivacySetting privacy = new PrivacySetting();
privacy.setMakeSlideshowPrivate(false);    // make slideshow public

String editedShowId = slideshow.editSlideshow(username, password,
    "01234", "New Title", "New Desc", tags, privacy);

Simply you can delete slideshow by ID.

String deletedShowId = slideshow.deleteSlideshow(username, password, "01234");

What’s next?

The Slideshare API provides four areas of functionality supporting slideshows, users, favorites and lead/campaign operations. The current version of Spring Social Slideshare only supports slideshow-specific operations.

The project is evolving. Don't hesitate to reach me, create an issue on GitHub, or send pull-requests for specific improvements.

Summary

If your application needs to integrate with SlideShare, Spring Social Slideshare is an easy, familiar approach. I created a sample project which demonstrates the basic operations explained in this post. Start here. Thank you for reading this post.

Get the Spring newsletter

Thank you for your interest. Someone will get back to you shortly.

Get ahead

VMware offers training and certification to turbo-charge your progress.

Learn more

Get support

Tanzu Spring Runtime offers support and binaries for OpenJDK™, Spring, and Apache Tomcat® in one simple subscription.

Learn more

Upcoming events

Check out all the upcoming events in the Spring community.

View all