這是一篇老帖子,但僅供將來參考,我直接使用http post將圖片上傳到Picasa方面取得了成功。他們自己的Java API不斷返回錯誤。
我寫這個方法進行了詳細here:
File image = new File("/path/to/image.jpg");
byte[] imageContent = null;
try {
imageContent = Files.toByteArray(image);
} catch (Exception e) {
// do something
}
HttpClient httpClient = HttpClientBuilder.create().build();
HttpPost httpPost = new HttpPost("https://picasaweb.google.com/data/feed/api/user/default/albumid/default");
httpPost.addHeader("Authorization", "Bearer " + mAccessToken);
httpPost.addHeader("Content-Type", "image/jpeg");
httpPost.setEntity(new ByteArrayEntity(imageContent));
try {
HttpResponse httpResponse = httpClient.execute(httpPost);
// log the response
logd(EntityUtils.toString(httpResponse.getEntity()));
} catch (IOException e){
// do something
}
此方法使用Apache的HttpClient的。如果您的Android版本不支持它,你仍然可以包括這條線在搖籃文件編譯:
compile 'cz.msebera.android:httpclient:4.4.1.1'
我已經看到了這個項目已經,但他是在2009年,是寫了在Android 2.2。我寫了一個3和以上的應用程序,它必須是一些更高的代碼或API,這是更好的。 – Maury