How To Post Image From Drawable Folder To Facebook With Graph Api?
I'd like to post an image to facebook by using their graph api. But my image is in drawable folder. So far: public static void postToFacebook() { Bundle params = new Bundle();
Solution 1:
This is the correct way to upload a photo from a drawable. Note that the only parameters you need is "photo" and "caption".
Bundle params = new Bundle();
params.putByteArray("photo", getImageAsData());
params.putString("caption", "Test caption lololol");
mAsyncRunner.request("me/photos", params, "POST", new PhotoUploadListener(), null);
Solution 2:
Bundle b=newBundle();
b.putString("Picture","// Byte array value of ur image");
facebook.request("username/photos",b,"POST");
Solution 3:
Instead of using BitmapDrawable you can directly get the image from drawable to bitmap then convert it to bytearray. Some times bitmapdrawable causes unexpected problem.
Bitmapbitmap= BitmapFactory.decodeResource(ctx.getResources(),
R.drawable.image);
ByteArrayOutputStreamstream=newByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] bitMapData = stream.toByteArray();
now use this to post --
parameters.putByteArray("picture", bitMapData);
mAsyncFbRunner.request("me/feed", params, "POST", new WallPostListener());
Post a Comment for "How To Post Image From Drawable Folder To Facebook With Graph Api?"