0

According to several searches I've made, here is what I have written in order to send an image I've just save on my SD card

    public void postToWall() throws FileNotFoundException, MalformedURLException, IOException {
    loginToFacebook();
    if (facebook.isSessionValid()) {
        // Ok le login est bien enregistre
        Bundle bundle = new Bundle();
        bundle.putString("message","test");
        File file = (File) this.getIntent().getExtras().get("PICTURE_TAKEN");
        FileInputStream fis = new FileInputStream(file);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        int data2 = 0;
            while ((data2 = fis.read()) != -1)
                baos.write(data2);
            fis.close();
            byte[] bytes = baos.toByteArray();
            baos.close();
            bundle.putByteArray("Picture", bytes);
        mAsyncRunner.request("me/feed", bundle, "POST", new FacebookPostListener(), null);
    }
}

I succeed in posting the text message "message" but not the image ! (the extra "PICTURE_TAKEN" being the File related to the picture taken)

morg
  • 1,173
  • 4
  • 18
  • 36
  • i need your help: http://stackoverflow.com/questions/18657388/how-to-allow-user-to-post-an-image-on-wall-using-sdcard-folder – Sun Sep 07 '13 at 06:03

2 Answers2

0

If you're starting a new project, you should use version 3.0 of the Facebook SDK for Android where posting a photo is very easy: see Request.newUploadPhotoRequest.

Ming Li
  • 15,672
  • 3
  • 37
  • 35
0

Ok so I've solved my problem just replace "me/feed" by "photos" in mAsyncRunner.request("me/feed", bundle, "POST", new FacebookPostListener(), null);

morg
  • 1,173
  • 4
  • 18
  • 36