Saturday, 17 August 2013

Integrate tumblr in your App

Hello All,
  
     Today i have do some R&D on Tumblr (blogging platform that allows users to post text, images, videos, links, quotes and audio to their tumblelog) also integrate in my android app. So i would like to share my knowledge with you all. Its very easy to integrate tumblr in your android app. Site also have provided very good documentation in their developer forum.Below link provides the full documentation and api console to test your request easily.

    http://www.tumblr.com/developers

First of all you need to register your app on below link.

    http://www.tumblr.com/oauth/register

Now to use tumblr API in your android application you need library of tumblr. You can download the java project and build jar file form below link. You can also download direct jar file form link.

    https://github.com/tumblr/jumblr

Put this jar file in your lib folder in android project. And build it. Now you can access JumblrClient class to call tumblr api. Some request of this api require access token because they use OAuth 1.0.So you need access token to call some of their request.

Below snippets code shows how to made connection with api and get retrieve logged in user basic information.

// Authenticate via OAuth
  JumblrClient client = new JumblrClient("consumer key", "consumer secret");
  client.setToken("access token", "token secret");

// Make the request
  User user = client.user();
  Log.e("USER", "" + user.getName());
  Log.e("USER", "" + user.getDefaultPostFormat());
  Log.e("USER", "" + user.toString());
  Log.e("USER", "" + user.getFollowingCount());
  Log.e("USER", "" + user.getLikeCount());

Now after successfully getting user basic information try to get your blogs information  using below code.

// Make request to api
  Blog blog = client.blogInfo("your blog name"); // it is something like david.tumblr.com
  Log.e("USER", "" + blog.avatar());
  Log.e("USER", "" + blog.getDescription());
  Log.e("USER", "" + blog.getName());
  Log.e("USER", "" + blog.getTitle());
 
  Below code show how to post simple text post on your blog. To post text on your blog you require to authorize your app which is done by code shown above with access token and token secret.
// Upload new text post
  Map detail = new HashMap();
  detail.put("title", "test from mobile app");
  detail.put("body", "This is a test to upload new post on my blog.");
  try {
   client.postCreate("bhargav3132.tumblr.com", detail);
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  Okey now you can explore more from here and share or create blog from your android app.

 Cheers!!!

No comments :

Post a Comment