Uploading Pictures To Facebook Using Graph Api With Android Sdk
I am trying to upload a photo to facebook using graph api and keep getting OutOfMemory exception. The code for the upload is this: private void PostPhoto(SessionHandler facebook, U
Solution 1:
Try this, it works for me:
byte[] data = null;
try {
ContentResolvercr= mainActivity.getContentResolver();
InputStreamfis= cr.openInputStream(photoUri);
Bitmapbi= BitmapFactory.decodeStream(fis);
ByteArrayOutputStreambaos=newByteArrayOutputStream();
bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
data = baos.toByteArray();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Bundleparams=newBundle();
params.putString("method", "photos.upload");
params.putByteArray("picture", data);
This is using the Rest API, the facebook sdk has the method for calling it so just change your request line from:
facebook.mFacebook.request("me/photos", params, "POST");
to:
facebook.mFacebook.request(params);
and hopefully that will solve the problem.
Post a Comment for "Uploading Pictures To Facebook Using Graph Api With Android Sdk"