How can I post an image with text on facebook? I know how to post text, links, but I want to post an image as well.
Here is what I have tried:
byte[] data = null;
Bitmap bi = BitmapFactory.decodeFile("R.drawable.plate1");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
data = baos.toByteArray();
parameters.putByteArray("picture", data);
int plate = getResources().getIdentifier("com.b2creativedesigns.eyetest:drawable/plate1", null, null);
parameters.putString("picture", String.valueOf(plate));
Neither of them works. When I try to post, nothing happens. Nothing is posted. With the code below, it works.
Posting the image from a website is easy, but it will not work, when the website gets shutdown or the links modified.
parameters.putString("picture", "https://lh3.ggpht.com/f79UCpnLisZxO2P2C43f55YLvFpNco_cTcC-t9Ck-Qmqe5jwKbfnUvCh5N6-Te-mOw=w124");
3rd example:
byte[] data = null;
Bitmap bi = BitmapFactory.decodeFile("R.drawable.plate1");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
data = baos.toByteArray();
parameters.putString("method", "photos.upload");
parameters.putByteArray("picture", data);
EDIT: Sorry, I shouldn’t have gave advice on how to use the REST API since it’s deprecated. This is how you upload a photo to your own wall using the Graph API.
Please try this and see if it works. This was taken straight out of our HackBook example in our documentation. For the compression of the image, you can use our
Utility.scaleImagemethod inside our SDK which will do all the compression and scaling to match Facebook’s standards.==================================================================================
ORIGINAL MESSAGE:
photos.uploadis using the REST API and is deprecated so I would recommend using the Graph API to upload photos but here’s the quick and dirty solution using the REST API.Once you have the byte array in a variable like
data, do the following:Let me know if that helps.