Ishaan
Ishaan

Reputation: 3918

Facebook4j library post photo issue

I am using the facebook4j library for integrating facebook api in java. However, I face issues when I try to post a photo with a place attribute.

Media media = new Media(new File(<image-path-here>));
PhotoUpdate update = new PhotoUpdate(media);
update.message("photo upload test");
update.setPlace("Bangalore");
facebook.postPhoto(update);    

But I get the following exception:SEVERE: Servlet.service() for servlet [post] in context with path [/Sample] threw exception [message - An unknown error has occurred.FacebookException{statusCode=500, errorType='OAuthException', errorMessage='An unknown error has occurred.', errorCode=1, errorSubcode=-1, version=2.2.0}

Turns out that without the 'setplace' its works completely fine. I am not sure if I am doing the right way and searched the web to get some samples as well. But could not find one, can anyone please suggest what am I doing wrong here? I can post the photo on facebook without setting the location but I need to set location for image.

Thanks

Upvotes: 1

Views: 953

Answers (2)

Maxx
Maxx

Reputation: 411

With my solution, I upload the image to server and upload that file to facebook. you can see the below example.

    /**
 * NOTE: Post Photo To Wall Facebook
 * @param String idToObject
 * @param File filePhoto (This is real file from server)
 * @return List<String>
 */
public String postToWallPhoto(String idToObject, UploadedFile uploadedFile) {
    PhotoUpdate photoUpdate = null;
    try {
        Media media=new Media(uploadedFile.getFile());
        photoUpdate = new PhotoUpdate(media);
        photoUpdate.message(postItem.getGroupMessage());

        String idPost = facebook.postPhoto(idToObject, photoUpdate);

    } catch (FacebookException e) {
        e.printStackTrace();
    }
    return idPost;
}

Upvotes: 1

Maxx
Maxx

Reputation: 411

Can you try this.

PostUpdate post= update = new PostUpdate("@Minh Nguyen")
        .picture(new URL("Img_url"));
facebook.postFeed(id,post);

Upvotes: 0

Related Questions