How to share individual images on Facebook?

How do I share images on Facebook using Facebook Android SDK?

  • I read Facebook Android SDK's known issue: Binary API parameters (such as uploading pictures) is not yet supported. Any suggestions? Thanks!!!

  • Answer:

    public void postImageToWall() { facebook.authorize( this, new String[] { "user_photos,publish_checkins,publish_actions,publish_stream" }, new DialogListener() { @Override public void onFacebookError(FacebookError e) { // TODO Auto-generated method stub } @Override public void onError(DialogError dialogError) { // TODO Auto-generated method stub } @Override public void onComplete(Bundle values) { postImageonWall(); } @Override public void onCancel() { // TODO Auto-generated method stub } }); } private void postImageonWall() { byte[] data = null; Bitmap bi = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); ByteArrayOutputStream baos = new ByteArrayOutputStream(); bi.compress(Bitmap.CompressFormat.JPEG, 100, baos); data = baos.toByteArray(); Bundle params = new Bundle(); params.putString(Facebook.TOKEN, facebook.getAccessToken()); params.putString("method", "photos.upload"); params.putByteArray("picture", data); params.putString("caption", "Dessert Dash in Android "); AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook); mAsyncRunner.request(null, params, "POST", new SampleUploadListener(), null); } class SampleUploadListener implements AsyncFacebookRunner.RequestListener { @Override public void onComplete(String response, Object state) { } @Override public void onIOException(IOException e, Object state) { } @Override public void onFileNotFoundException(FileNotFoundException e, Object state) { } @Override public void onMalformedURLException(MalformedURLException e, Object state) { } @Override public void onFacebookError(FacebookError e, Object state) { } }

Ayan Bhattacharyya at Quora Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.