久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Android,以編程方式將照片上傳到 imgur 上

Android, uploading a photo to host on imgur programatically(Android,以編程方式將照片上傳到 imgur 上)
本文介紹了Android,以編程方式將照片上傳到 imgur 上的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我嘗試了不同的方法來通過 imgur 上傳和檢索鏈接,但盡管查看了 imgur api,但都沒有成功.http://api.imgur.com/examples#uploading_java

I have tried different methods to upload and retrieve a link via imgur but none have been successfull despite looking at the imgur api. http://api.imgur.com/examples#uploading_java

但以下方法部分有效..我正在嘗試檢索,

But the following methods partly works.. im trying to retrieve,

errors:如果發(fā)生任何錯誤.圖像鏈接:托管圖像的鏈接刪除鏈接:刪除托管圖片的鏈接

errors: if any errors occured. link to image: the link to the image hosted delete link: the link to delete the image hosted

但我只以刪除鏈接"結(jié)束,因為其他都是空白的,看看吧:

But i only end up with the "delete link", as the others are blank, check it out:

public void post(String path) {


    List<NameValuePair> postContent = new ArrayList<NameValuePair>(2);  
    postContent.add(new BasicNameValuePair("key", DEV_KEY));  
    postContent.add(new BasicNameValuePair("image", path));


    String url = "http://api.imgur.com/2/upload";
    HttpClient httpClient = new DefaultHttpClient();
    HttpContext localContext = new BasicHttpContext();
    HttpPost httpPost = new HttpPost(url);

    try {
        MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);

        for(int index=0; index < postContent.size(); index++) {
            if(postContent.get(index).getName().equalsIgnoreCase("image")) {
                // If the key equals to "image", we use FileBody to transfer the data
                entity.addPart(postContent.get(index).getName(), new FileBody(new File (postContent.get(index).getValue())));
            } else {
                // Normal string data
                entity.addPart(postContent.get(index).getName(), new StringBody(postContent.get(index).getValue()));
            }
        }

        httpPost.setEntity(entity);

        HttpResponse response = httpClient.execute(httpPost, localContext);
        mImgurResponse = parseResponse (response);


        Iterator it = mImgurResponse.entrySet().iterator();
        while(it.hasNext()){
            HashMap.Entry pairs = (HashMap.Entry)it.next();

            Log.i("INFO",pairs.getKey().toString());
            if(pairs.getValue()!=null){
                reviewEdit.setText(pairs.getValue().toString());

            Log.i("INFO",pairs.getValue().toString());
            }
        }


    } catch (IOException e) {
        e.printStackTrace();
    }
}

private Map<String,String> parseResponse(HttpResponse response) {
        String xmlResponse = null;

        try {
            xmlResponse = EntityUtils.toString(response.getEntity());
        } catch (ParseException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        if (xmlResponse == null) return null;

        HashMap<String, String> ret = new HashMap<String, String>();
        ret.put("error", getXMLElementValue(xmlResponse, "error_msg"));
        ret.put("delete", getXMLElementValue(xmlResponse, "delete_page"));
        ret.put("original", getXMLElementValue(xmlResponse, "original_image"));

        return ret;
    }

private String getXMLElementValue(String xml, String elementName) {
        if (xml.indexOf(elementName) >= 0)
            return xml.substring(xml.indexOf(elementName) + elementName.length() + 1, 
                    xml.lastIndexOf(elementName) - 2);
        else
            return null;
    }

我最后得到的只是一個只有刪除鏈接的哈希圖 mImageResponse...

All i get back in the end is a hashmap mImageResponse with only the delete link...

關(guān)于我做錯了什么有什么想法嗎?

any ideas on what im doing wrong?

推薦答案

解決這個問題只是將 URL 更改為:imgur.com/api/upload.xml

The fix to this was merely to change the URL to: imgur.com/api/upload.xml

這篇關(guān)于Android,以編程方式將照片上傳到 imgur 上的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環(huán)繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數(shù)據(jù)庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 91精品一区 | 亚洲欧美中文日韩在线v日本 | 亚洲欧洲精品一区 | 国产一区二区在线免费视频 | 春色av | 性在线| 久久久久久久久久久久亚洲 | 国产精品精品久久久 | 99久久婷婷国产综合精品 | 在线视频日韩 | 中文字幕1区 | 久久国产精品亚洲 | 高清18麻豆 | 中文字幕成人网 | 国产精品自产拍在线观看蜜 | 欧美亚洲国产一区 | 欧美精品久久久久 | 亚洲精品久久 | 男女性毛片| 中文字幕高清免费日韩视频在线 | 久久久久久免费精品一区二区三区 | 一级黄色毛片子 | 亚洲国产aⅴ成人精品无吗 国产精品永久在线观看 | 亚洲成人播放器 | 欧美另类日韩 | 中文字幕精品视频 | 中文字幕在线视频观看 | 国产精品久久网 | 国产视频一区二区 | 亚洲国产精品一区在线观看 | 亚洲男人天堂 | 欧美日韩在线一区二区三区 | 国产精品一区二区无线 | 色婷婷精品 | 欧美成人a| 国产精品久久久久久久久久 | 精品久久久久一区二区国产 | 91精品久久久久久久久 | 国产精品不卡视频 | 午夜寂寞影院在线观看 | 欧美一区久久 |