你的答案工作一種享受,幫我無盡的金額,但是我發現我的解決方案,我並不需要
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;
}
再次感謝您的幫助。