Upload photo to Facebook with Facebook Android SDK in Android

sanjana picture sanjana · Jun 24, 2010 · Viewed 56.4k times · Source

I'm new to Android. I'm searching for load photo to facebook by authorization, getting access_token. How to do this? Please give me a sample code in Java.

Answer

trgraglia picture trgraglia · Feb 10, 2011

Just posted here the simple way to upload a photo:

android facebook publish photo

Code:

byte[] data = null;

Bitmap bi = BitmapFactory.decodeFile(photoToPost);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
data = baos.toByteArray();

Bundle params = new Bundle();
params.putString("method", "photos.upload");
params.putByteArray("picture", data);

AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
mAsyncRunner.request(null, params, "POST", new SampleUploadListener(), null);