What I have
I have a photo that needs to posted to Social API
like FB,TWITTER,TUMBLR,FLICKR
What I wanted
I wanted to post my photo to Tumblr
What I tried
I came across Jumblr Client
which is an official client for Tumblr
My problem
The document directly says
JumblrClient client = new JumblrClient("consumer_key","consumer_secret");
client.setToken("oauth_token", "oauth_token_secret");
I have consumer_key
& consumer_secret
, how to authenticate and get oauth_token , oauth_token_secret
Thanks to Clinkz. Its pretty forward up there in these links but if still someone is having issue , this is the code which I used in my Android app and its working fine. For Android at 1st we have to add these two line in app level gradle file:
implementation 'com.daksh:loglr:2.1.4'
implementation 'com.tumblr:jumblr:0.0.13'
private void loginToTumblr() {
Loglr loglr = Loglr.INSTANCE;
if(loglr != null) {
loglr.setConsumerKey("TUBMLR_CONSUMER_KEY"); // Replace with your App's Key
loglr.setConsumerSecretKey("TUBMLR_CONSUMER_SECRET"); // Replace with your App's Key
loglr.setUrlCallBack("https://www.callback.com/"); // Replace with your App's Callback
loglr.setLoginListener(new LoginListener() {
@Override
public void onLoginSuccessful(com.tumblr.loglr.LoginResult loginResult) {
String oAuthToken = loginResult.getOAuthToken();
String oAuthTokenSecret = loginResult.getOAuthTokenSecret();
Log.w(TAG, oAuthToken + "\n" + oAuthTokenSecret);
shareOnTumblr(oAuthToken , oAuthTokenSecret);
}
});
loglr.setExceptionHandler(new ExceptionHandler() {
@Override
public void onLoginFailed(RuntimeException e) {
Log.e(TAG, "Loglr Exeception: " + e.getMessage());
Toast.makeText(this, "Sorry! can't login to the tumblr.", Toast.LENGTH_LONG).show();
}
});
loglr.initiate(this);
}
else
Toast.makeText(this, "Something went wrong while Loggin in to Tumblr.", Toast.LENGTH_LONG).show();
}
After Login if you want to share some Image with some caption, you can use the following code:
private void shareOnTumblr(String token, String tokenSecret) {
IResult iResult = new IResult() {
@Override
public void onSuccess(String result) {
loadingBar.hide();
Toast.makeText(this, result, Toast.LENGTH_LONG).show();
}
@Override
public void onError(String error) {
Toast.makeText(this, error, Toast.LENGTH_LONG).show();
}
};
String caption = "IMAGE CAPTION GOES HERE";
String imagePath = "IMAGE PATH GOES HERE"; //It must a String
String params[] = new String[]{token, tokenSecret , caption, imagePath};
new TumblrPostAsyncTask(iResult).execute(params);
}
public static class TumblrPostAsyncTask extends AsyncTask<String, String, Boolean> {
IResult iResult;
TumblrPostAsyncTask(IResult iResult){
this.iResult = iResult;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Boolean doInBackground(String... params) {
boolean result;
try {
JumblrClient client = new JumblrClient("TUBMLR_CONSUMER_KEY", "TUBMLR_CONSUMER_SECRET");
client.setToken(params[0], params[1]);
PhotoPost post = client.newPost(client.user().getBlogs().get(0).getName(),PhotoPost.class);
Log.w(TAG, params[2] + " " + params[3]);
post.setCaption(params[2]);
post.setData(new File(params[3]));
post.save();
result = true;
} catch (Exception e) {
Log.w(TAG, "Tumblr's Error: " + e.getMessage());
result = false;
}
return result;
}
@Override
protected void onPostExecute(Boolean success) {
super.onPostExecute(success);
Log.w(TAG, "On Post Execute: " + success);
if(success)
iResult.onSuccess("Successfully Posted on Tumblr.");
else
iResult.onError("Sorry! couldn't Post on Tumblr.");
}
}
Interface looks like this:
public interface IResult {
void onSuccess(String result);
void onError(String error);
}