我正在使用jumblr开发简单的应用程序,通过tumblr
发布文字和照片。文字发布工作完美。但是图像发布为文件工作但是通过url发布图像不起作用。
我的代码
client = new JumblrClient(TumblrConstants.tumblrConsKey,
TumblrConstants.tumblrSecKey);
client.setToken(objSession.getToken(),
objSession.getTokenSecret());
// This part is working perfectly
PhotoPost photoPost =client.newPost(client.user().getName(),
PhotoPost.class);
File file=new File(picturePath);
photoPost.setPhoto(new Photo(file));
photoPost.save();
// This part is not working
PhotoPost photoPost1 = client.newPost(client.user().getName(),
PhotoPost.class);
String imgUrl = "http://dummyimage.com/300.png/09f/fff";
photoPost1.setCaption("sample");
//photoPost.setSource(imgUrl);
photoPost1.setLinkUrl(imgUrl);
photoPost1.save();
// TextPost post = client.newPost(client.user().getName(),
// TextPost.class);
// post.setTitle("Sample title");
// post.setBody(txt);
// post.save();
错误:
01-22 16:25:44.929: E/AndroidRuntime(10082): FATAL EXCEPTION: AsyncTask #1
01-22 16:25:44.929: E/AndroidRuntime(10082): java.lang.RuntimeException: An error occured while executing doInBackground()
01-22 16:25:44.929: E/AndroidRuntime(10082): at android.os.AsyncTask$3.done(AsyncTask.java:299)
01-22 16:25:44.929: E/AndroidRuntime(10082): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
01-22 16:25:44.929: E/AndroidRuntime(10082): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
01-22 16:25:44.929: E/AndroidRuntime(10082): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
01-22 16:25:44.929: E/AndroidRuntime(10082): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
01-22 16:25:44.929: E/AndroidRuntime(10082): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
01-22 16:25:44.929: E/AndroidRuntime(10082): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
01-22 16:25:44.929: E/AndroidRuntime(10082): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
01-22 16:25:44.929: E/AndroidRuntime(10082): at java.lang.Thread.run(Thread.java:856)
01-22 16:25:44.929: E/AndroidRuntime(10082): Caused by: org.scribe.exceptions.OAuthConnectionException: There was a problem while creating a connection to the remote service.
01-22 16:25:44.929: E/AndroidRuntime(10082): at org.scribe.model.Request.send(Request.java:69)
01-22 16:25:44.929: E/AndroidRuntime(10082): at org.scribe.model.Request.send(Request.java:75)
01-22 16:25:44.929: E/AndroidRuntime(10082): at com.tumblr.jumblr.request.RequestBuilder.postMultipart(RequestBuilder.java:56)
01-22 16:25:44.929: E/AndroidRuntime(10082): at com.tumblr.jumblr.JumblrClient.postCreate(JumblrClient.java:352)
01-22 16:25:44.929: E/AndroidRuntime(10082): at com.tumblr.jumblr.types.Post.save(Post.java:331)
01-22 16:25:44.929: E/AndroidRuntime(10082): at com.selva.TumblrLogin$PublishPicture.doInBackground(TumblrLogin.java:445)
01-22 16:25:44.929: E/AndroidRuntime(10082): at com.selva.TumblrLogin$PublishPicture.doInBackground(TumblrLogin.java:1)
01-22 16:25:44.929: E/AndroidRuntime(10082): at android.os.AsyncTask$2.call(AsyncTask.java:287)
01-22 16:25:44.929: E/AndroidRuntime(10082): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
01-22 16:25:44.929: E/AndroidRuntime(10082): ... 5 more
01-22 16:25:44.929: E/AndroidRuntime(10082): Caused by: java.io.IOException: No authentication challenges found
01-22 16:25:44.929: E/AndroidRuntime(10082): at libcore.net.http.HttpURLConnectionImpl.getAuthorizationCredentials(HttpURLConnectionImpl.java:427)
01-22 16:25:44.929: E/AndroidRuntime(10082): at libcore.net.http.HttpURLConnectionImpl.processAuthHeader(HttpURLConnectionImpl.java:407)
01-22 16:25:44.929: E/AndroidRuntime(10082): at libcore.net.http.HttpURLConnectionImpl.processResponseHeaders(HttpURLConnectionImpl.java:356)
01-22 16:25:44.929: E/AndroidRuntime(10082): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:292)
01-22 16:25:44.929: E/AndroidRuntime(10082): at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:486)
01-22 16:25:44.929: E/AndroidRuntime(10082): at libcore.net.http.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:134)
01-22 16:25:44.929: E/AndroidRuntime(10082): at org.scribe.model.Response.<init>(Response.java:29)
01-22 16:25:44.929: E/AndroidRuntime(10082): at org.scribe.model.Request.doSend(Request.java:115)
01-22 16:25:44.929: E/AndroidRuntime(10082): at org.scribe.model.Request.send(Request.java:65)
01-22 16:25:44.929: E/AndroidRuntime(10082): ... 13 more
答案 0 :(得分:1)
您可以使用jumblr - Tumblr java客户端
轻松完成此操作JumblrClient client = new JumblrClient(Constant.CONSUMER_KEY,Constant.CONSUMER_SECRET);
client.setToken(preferences.getString("token",null), preferences.getString("token_secret", null));
PhotoPost pp = client.newPost(client.user().getBlogs().get(0).getName(),PhotoPost.class);
pp.setCaption(caption);
// pp.setLinkUrl(link);
// pp.setSource(mImage); // String URL
pp.setPhoto(new Photo(imgFile));
pp.save();
答案 1 :(得分:0)
我能够创造&amp;我通过身份验证后,使用以下代码通过URL保存新的PhotoPost
。
final String source = "<YOUR IMAGE URL HERE>";
final PhotoPost post = client.newPost("<AUTHENTICATED BLOG NAME>", PhotoPost.class);
post.setSource(source);
post.save();