所以我一直试图使用imgur api匿名上传图片,而我似乎无法让它发挥作用。我觉得我确实做了我需要做的事情但是我被api关闭并出现以下错误:
{"错误":{"消息":"未发送API密钥,且未对用户进行身份验证","请求" :" // 2 / upload.json""方法":"后""格式":" JSON&#34 ;,"参数":" image = /storage/emulated/0/DCIM/Camera/IMG_20150404_191703.jpg"}}
我创建了一个应用程序,选择了一个非常有用的选项(https://api.imgur.com/oauth2/addclient)我使用了我的客户端ID,但不知怎的,它仍然不够。如果有人知道什么是问题,我将不胜感激!
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(IMGUR_POST_URI);
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("image", params[0]));
httpPost.setEntity(new UrlEncodedFormEntity(nvps, "UTF-8"));
httpPost.addHeader("Authorization", "Client-ID " + IMGUR_API_KEY);
HttpResponse response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
if (entity != null) {
BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuilder content = new StringBuilder();
String line;
while (null != (line = br.readLine())) {
content.append(line);
}
System.out.println(content);
}
} catch (Exception e) {
e.printStackTrace();
}