Facebook4j库发布照片问题 [英] Facebook4j library post photo issue
问题描述
我正在使用facebook4j库在Java中集成facebook api.但是,当我尝试发布具有地点属性的照片时会遇到问题.
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);
但是出现以下异常: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上发布照片,但是我需要设置图像的位置.
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.
谢谢
推荐答案
使用我的解决方案,我将图像上传到服务器,并将该文件上传到Facebook.您可以看到以下示例.
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;
}
这篇关于Facebook4j库发布照片问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!