2

I'm developing an app for which I need to be able to upload pics to picasa open album. Ive gone through many threads,forums... tried a couple of methods using http post but none seems to work.

Has anyone did it before? If so can you share a sample code.I just need to do the basic upload and dload of pics from picasa.

ash
  • 41
  • 3

2 Answers2

1

The above answer was for Picasa API v2, which is now deprecated. I was not able to successfully use the Java API for Picasa API v3, but I figured out a way to upload images to Picasa using http post. I've written about this method 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
}

This method uses Apache's HttpClient. If your Android version does not support it, you can still include this line in your Gradle file to compile it:

compile 'cz.msebera.android:httpclient:4.4.1.1'
thenewpotato
  • 101
  • 1
  • 9
  • Link as answers are best for comments not answers. I suggest editing the above answer to add the main parts so its in one place. The link doesn't contain that much code. – Syfer Aug 04 '17 at 00:08
  • @Syfer I apologize for my laziness, thank you for the tip, the answer has been updated. – thenewpotato Aug 04 '17 at 00:22
1

The following question looks to cover some of this. Picasa access in android: PicasaUploadActivity This thread also has information. http://www.mail-archive.com/android-developers@googlegroups.com/msg43707.html

It looks straight forward to fire off the intent to use the standard picasa uploader. I will try putting this in my app later today as I want this function.

Doing it yourself looks to be possible but clearly more complex documentation looks to be http://code.google.com/apis/picasaweb/docs/2.0/developers_guide_protocol.html

OK I have got it working with the following code in my app. This brings up the picasa uploader.

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");
}

In practice I am going to take the set component bit out which lets the use choose where and how to send which is what I want.

Community
  • 1
  • 1
Ifor
  • 2,825
  • 1
  • 22
  • 25
  • Im also guessing it will open picasa to upload to one of the accounts syncd with phone... but i need to upload to a public album... – ash Dec 04 '11 at 05:40
  • oops... no error.. Its opening the picasa upload option.. but still i need to upload to a public album... – ash Dec 04 '11 at 05:43
  • Hey can you also help me out with the activity name that i need to put to open googleplus update page like picasa... so that i can atleast upload to googleplus – ash Dec 04 '11 at 09:52
  • If you want to change album properties etc I expect you will need to use the full Api. You will need to read the developers guide I linked to and work it out. For your googleplus try doing a manual 'send' of somthing and check the logcat to see what activity is used.... – Ifor Dec 04 '11 at 19:17