你的答案工作一种享受,帮我无尽的金额,但是我发现我的解决方案,我并不需要
FacebookType post = fc.publish(pageid + "/feed", FacebookType.class,
Parameter.with("message", "your message"),Parameter.with("type", "photo"),
Parameter.with("link", photoLink.getLink()));
,我会recive一个错误(我应该有复制给你看),但photoLink.getLink()
在我的情况下返回null。
所以我更新的解决方案再次结束了
FacebookType photo = client.publish(groupId + "/photos",
FacebookType.class,
BinaryAttachment.with(imageName),
imageAsBytes,
"image/png"),
Parameter.with("message",
message));
只是我的2美分,感谢您的帮助!
编辑
而且同时玩弄我注意到,在该解决方案,我来到了我创建一个FacebookType photo
对象,这个对象没有得到任何地方使用,你只调用这是客户端的发布方法在您的程序中进一步创建。
我的最后一个类是低于,(我的应用程序从计算机拍摄图像,并给一组壁)
public void createImagePostInGroup(String message, String groupId, String imageFilePath){
byte[] imageAsBytes = fetchBytesFromImage(imageFilePath);
DefaultFacebookClient client =
new DefaultFacebookClient(accessToken, Version.LATEST);
client.publish(groupId + "/photos",
FacebookType.class,
BinaryAttachment.with(imageFilePath.substring(imageFilePath.length()-34),
imageAsBytes,
"image/png"),
Parameter.with("message",
message));
}
而我的图像被转换成一个字节数组在该方法中
private byte[] fetchBytesFromImage(String imageFile) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte fileContent[] = null;
try{
BufferedImage image = ImageIO.read(new File(imageFile));
ImageIO.write(image, "png", baos);
baos.flush();
fileContent = baos.toByteArray();
}catch (Exception e){
e.printStackTrace();
}
return fileContent;
}
再次感谢您的帮助。