0
HttpClient httpclient = new DefaultHttpClient();
HttpPost post = new HttpPost(
"http://api.flickr.com/services/upload/");
HttpResponse response;
try {
response = httpclient.execute(post);
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream inputstream = entity.getContent();
BufferedReader bufferedreader = new BufferedReader(
new InputStreamReader(inputstream));
StringBuilder stringbuilder = new StringBuilder();
String currentline = null;
try {
while ((currentline = bufferedreader.readLine()) != null) {
stringbuilder.append(currentline + "\n");
}
} catch (IOException e) {
e.printStackTrace();
}
String result = stringbuilder.toString();
System.out.println(result);
}
// HttpPost hp = new HttpPost(fma.upload_url);
try {
Bitmap bm = BitmapFactory.decodeFile(file.toString()
+ "/09102011079.jpg");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 50, baos);
byte[] b = baos.toByteArray();
ByteArrayBody bab = new ByteArrayBody(b, "");
MultipartEntity me = new MultipartEntity();
me.addPart("media", bab);
post.setEntity(me);
/*String s = "<root>" + "<entities>" + "<media>"
+ "<size>" + "<large>" + "<width>700</width>"
+ "<height>500<height>"
+ "<resize>\"fit\"</resize>" + "</large>"
+ "</size>" + "</media>" + "</entities>"
+ "</root>";*/
/*
* try { se = new StringEntity(s); } catch
* (UnsupportedEncodingException e1) { // TODO //
* Auto-generated // catch // block //
* e1.printStackTrace(); // } // }
*/
// ByteArrayEntity bae = new ByteArrayEntity(b); //
// hp.setEntity(se); // hp.setEntity(bae);
fma.consumer.sign(post);
DefaultHttpClient client = new DefaultHttpClient();
client.execute(post);
} catch (OAuthMessageSignerException e) {
System.out.println(e.getMessage());
} catch (OAuthExpectationFailedException e) {
System.out.println(e.getMessage());
} catch (OAuthCommunicationException e) {
System.out.println(e.getMessage());
} catch (ClientProtocolException e) {
System.out.println(e.getMessage());
} catch (IOException e) {
System.out.println(e.getMessage());
}
} catch (Exception e) {
}
這是我上傳的代碼,但我得到這個錯誤------>Flickr的REST API(上傳照片)
12月11日至14日每天時間:20:33.515:信息/System.out(444):
err code =「100」msg =「API密鑰無效(密鑰格式無效)」
請幫幫我。提前致謝。
我改正了我的代碼現在它有另一個被稱爲錯誤代碼2沒有指定的照片 – Rocker
如何指定照片參數請給我一些例子... – Rocker
如果你成功,你能分享代碼嗎? –