ash
ash

Reputation: 41

Uploading to picasa from android app

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.

Upvotes: 2

Views: 1463

Answers (2)

thenewpotato
thenewpotato

Reputation: 161

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'

Upvotes: 1

Ifor
Ifor

Reputation: 2835

The following question looks to cover some of this. Picasa access in android: PicasaUploadActivity This thread also has information. http://www.mail-archive.com/[email protected]/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.

Upvotes: 1

Related Questions