将照片从android上传到picasa?

时间:2012-12-31 11:19:59

标签: android google-api image-uploading picasa

我是Android编程的新手。我正在寻找一种向Picasa发送图片的简单方法,我查看了很多项目。我只是想发送一个JPEG或PNG按钮,我点击,发送并显示一条消息即可。 我知道这需要一个Google API和客户端身份验证,但很多人都会显示相同的意向发送。 请帮忙(对不起英语:P)

我发现了这个: http://code.google.com/p/google-api-java-client/source/browse?repo=samples#hg/picasa-android-sample

有人知道如何使用它吗?但是从基础知识来看,我迷失了。

2 个答案:

答案 0 :(得分:1)

在线上将照片上传到Picasa的唯一现有代码就是这个......

尝试使用此功能是否符合您的要求。如果可以,请使用按钮点击事件并在notification.finished()事件上显示消息,以确保文件已上传。

答案 1 :(得分:1)

相当旧的帖子,但仅供将来参考,我成功地直接使用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版本不支持它,您仍然可以在Gradle文件中包含此行以进行编译:

compile 'cz.msebera.android:httpclient:4.4.1.1'