使用tumblr发布图像

时间:2013-07-11 10:18:31

标签: android http-post tumblr

 {"meta":{"status":401,"msg":"Not Authorized"},"response":[]}

Tumblr在发布图片时给出了上述结果。

DefaultHttpClient client = new DefaultHttpClient();
HttpResponse resp = null;
String result = null;
HttpPost hpost = new HttpPost("http://api.tumblr.com/v2/blog/" + username              
                                                         +".tumblr.com/post");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("type", "photo"));
nameValuePairs.add(new BasicNameValuePair("caption", "hello"));
nameValuePairs.add(new BasicNameValuePair("source", "url_of_the_image"));


        String debug = "";
        try {
            hpost.setEntity(new UrlEncodedFormEntity(
                    nameValuePairs));
            consumer.sign(hpost);
            resp = client.execute(hpost);
            result = EntityUtils.toString(resp.getEntity());
            Log.v("result >>", result);
        } catch (UnsupportedEncodingException e) {
            debug += e.toString();
        } catch (OAuthMessageSignerException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (OAuthExpectationFailedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (OAuthCommunicationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

我需要在tumblr中发布图片。给我一些解决方案。

1 个答案:

答案 0 :(得分:0)

您是否考虑过使用第三方图书馆? Temboo SDK(需要免费帐户)包括通过传递照片URL或照片的Base64编码内容来创建Tumblr照片帖子的方法。看看:

https://www.temboo.com/library/Library/Tumblr/Post/CreatePhotoPostWithURL/ https://www.temboo.com/library/Library/Tumblr/Post/CreatePhotoPostWithImageFile/

完全披露 - 我在Temboo工作。