javafacebookimagepublishrestfb

Publishing a post with a picture to the facebook page with restFb


When I publish a picture to my wall by

FacebookType publish = fc.publish("me/photos", FacebookType.class,
                      BinaryAttachment.with(attachmentName, temporaryStream),
                      Parameter.with("message", "my myssage"));

the post is created as expected. I can see a message and the published pictute under the message .

but when I want to do the same but on some pages wall instead the user wall by.

FacebookType publish = fc.publish(pageId + "/photos", FacebookType.class,
                      BinaryAttachment.with(attachmentName, temporaryStream),
                      Parameter.with("message", "my myssage"));

the post is published, but I can see only text. Not the picture. The picture can be seen only when I click on the date of the post. I can also reach this photo by clicking on the photos on the top of the page and then "name of the page" photos tab.

Is there any way how to see the photo as the part of the post also when I post it on a page?


Solution

  • I finally found a solution. To publish post with a photo to the section with normal "text only" posts you need publish a photo to your wall (your user wall not the wall of the page), then get its link and finally create a feed to the page with the the picture link.

    here is the sample code:

    FacebookType photo = fc.publish(pageid + "/photos" , FacebookType.class,
                BinaryAttachment.with(photoName, photoInputStream));
    Link photoLink = fc.fetchObject(photo.getId(), Link.class);
    FacebookType post =  fc.publish(pageid + "/feed", FacebookType.class,
                Parameter.with("message", "your message"),Parameter.with("type", "photo"),
                Parameter.with("link", photoLink.getLink()));
    

    edit: I forgot about one thing. When you later delete the post, you do not delete to photo. To do that you have to do that manually.