我正在尝试将设备中的图像发布到用户的墙上。我发现:http ://codenameone.blogspot.com/2011/09/lwuit-and-facebook-api-by-chen-fishbein_18.html ,但它不支持发布图片,所以我写了一个简单的方法,如这个:
public void postOnWallWithPhoto(String userId, String message, byte[] img) throws IOException {
checkAuthentication();
FacebookRESTService con = new FacebookRESTService(token, userId, FEED, true);
con.setContentType("image/jpeg");
con.addArgument("message", message);
con.addArgument("type", "photo");
con.addArgument("picture", img);
if (slider != null) {
SliderBridge.bindProgress(con, slider);
}
for (int i = 0; i < responseCodeListeners.size(); i++) {
con.addResponseCodeListener((ActionListener) elementAt(i));
}
current = con;
NetworkManager.getInstance().addToQueueAndWait(con);
}
这个方法是这样调用的:
FileConnection fc = (FileConnection) Connector.open(path);
InputStream is = fc.openInputStream();
byte[] b = new byte[(int) fc.fileSize()];
is.read(b);
FaceBookAccess.getInstance().postOnWallWithPhoto(me.getId(), "test2", b);
在我发送请求后,墙上只显示文本(在此示例中为 test2)。在应该是图像的地方,有一条消息:“invalid invalid”。
有谁知道,我做错了什么?或者有人可以与我分享一个代码,它可以帮助我在 Facebook 墙上发布图像吗?