Jumblr实现android
作者:互联网
是)我有的
我有一张照片需要发布到社交API,如FB,TWITTER,TUMBLR,FLICKR
我想要的
我想把照片发给Tumblr
我尝试了什么
我遇到了Jumblr Client,这是Tumblr的官方客户
我的问题
该文件直接说
JumblrClient client = new JumblrClient("consumer_key","consumer_secret");
client.setToken("oauth_token", "oauth_token_secret");
我有consumer_key& consumer_secret,如何进行身份验证并获取oauth_token,oauth_token_secret
解决方法:
感谢Clinkz.它在这些链接中非常向前,但如果还有人有问题,这是我在我的Android应用程序中使用的代码,它的工作正常.对于Android 1,我们必须在app level gradle文件中添加这两行:
实现’com.daksh:loglr:2.1.4′
实现’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();
}
登录后如果要与某些标题共享某些图像,可以使用以下代码:
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 one rror(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.");
}
}
界面如下所示:
public interface IResult {
void onSuccess(String result);
void one rror(String error);
}
标签:android,tumblr,jumblr 来源: https://codeday.me/bug/20190623/1270594.html