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 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.
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.
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
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
downloadUrl. If you want to embed the presentation in HTML, use the
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
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
totalResults property that gives you the number of results returned and the total results of the result collection.
You can upload a presentation by specifying a
String, and an implementation of Spring’s
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");
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.
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.