【问题标题】:Uploading to picasa from android app从 android 应用上传到 picasa
【发布时间】:2012-01-11 08:21:54
【问题描述】:

我正在开发一个应用程序,我需要能够将图片上传到 picasa 打开相册。 我经历了很多线程、论坛...尝试了几种使用 http post 的方法,但似乎都没有。

以前有人做过吗?如果可以,您可以分享一个示例代码。我只需要从 picasa 进行基本的图片上传和下载。

【问题讨论】:

标签: android api picasa


【解决方案1】:

以上答案适用于 Picasa API v2,现已弃用。我无法成功地将 Java API 用于 Picasa API v3,但我想出了一种使用 http post 将图像上传到 Picasa 的方法。这个方法我写过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'

【讨论】:

  • 链接作为答案最适合 cmets 而不是答案。我建议编辑上述答案以添加主要部分,以便将其放在一个地方。该链接不包含那么多代码。
  • @Syfer 我为我的懒惰道歉,谢谢你的提示,答案已更新。
【解决方案2】:

以下问题似乎涵盖了其中的一些内容。 Picasa access in android: PicasaUploadActivity 这个线程也有信息。 http://www.mail-archive.com/android-developers@googlegroups.com/msg43707.html

它期待直接触发使用标准 picasa 上传器的意图。我将在今天晚些时候尝试将其放入我的应用程序中,因为我需要此功能。

自己做看起来是可能的,但显然更复杂的文档看起来是http://code.google.com/apis/picasaweb/docs/2.0/developers_guide_protocol.html

好的,我已经在我的应用程序中使用以下代码。这会打开 picasa 上传器。

Intent temp = new Intent(Intent.ACTION_SEND);
temp.setType("image/png");
temp.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
temp.putExtra(Intent.EXTRA_STREAM, fileUri);
temp.setComponent(new ComponentName(
    "com.google.android.apps.uploader",
    "com.google.android.apps.uploader.clients.picasa.PicasaSettingsActivity"));
try {
   startActivity(temp);
} catch (android.content.ActivityNotFoundException ex) {
    Log.v(TAG, "Picasa failed");
}

在实践中,我将取出设置组件位,让用户选择在哪里以及如何发送这是我想要的。

【讨论】:

  • 我也猜测它会打开 picasa 以上传到与手机同步的帐户之一……但我需要上传到公共相册……
  • 哎呀......没有错误......它打开了picasa上传选项......但我仍然需要上传到公共相册......
  • 嘿,你能帮我找出打开 googleplus 更新页面(如 picasa)所需的活动名称吗...这样我至少可以上传到 googleplus
  • 如果您想更改专辑属性等,我希望您需要使用完整的 Api。您将需要阅读我链接到的开发人员指南并加以解决。对于您的 googleplus,请尝试手动“发送”一些东西并检查 logcat 以查看使用了什么活动....
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-08
相关资源
最近更新 更多