Upload image anonymously to Imgur
so i've been trying to use the imgur api to upload an image anonymously and I can't seem to get it to work. I feel like I do exactly what I need to do an yet I get shut down by the api with the following error:
{"error":{"message":"No API key was sent, and no user is authenticated","request":"//2/upload.json","method":"post","format":"json","parameters":"image = /storage/emulated/0/DCIM/Camera/IMG_20150404_191703.jpg"}}
I created an app an selected the anontmous usage option (https://api.imgur.com/oauth2/addclient) I use my client ID but somehow it's still not enough. If anyone as an idea on what is the problem it would be greatly appreciated!
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();
}
链接地址: http://www.djcxy.com/p/81442.html
上一篇: 在Swift中使用头进行HTTP请求
下一篇: 将图像匿名上传到Imgur