Facebook4j库发布照片问题

时间:2014-10-31 14:05:40

标签: facebook facebook-graph-api

我正在使用facebook4j库在java中集成facebook api。但是,当我尝试发布带有地点属性的照片时,我遇到了问题。

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);    

但我得到以下异常: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}

事实证明,如果没有“设置”,它的作品完全没问题。我不确定我是否采取了正确的方式并在网上搜索了一些样本。但找不到一个,有人可以建议我在这里做错了什么吗?我可以在Facebook上发布照片而不设置位置,但我需要设置图像的位置。

由于

2 个答案:

答案 0 :(得分:1)

使用我的解决方案,我将图像上传到服务器并将该文件上传到Facebook。你可以看到下面的例子。

    /**
 * 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;
}

答案 1 :(得分:0)

你能试试吗?

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