Java 使用restFb将带有图片的帖子发布到facebook页面
当我发布一张照片到我的墙上Java 使用restFb将带有图片的帖子发布到facebook页面,java,facebook,image,publish,restfb,Java,Facebook,Image,Publish,Restfb,当我发布一张照片到我的墙上 FacebookType publish = fc.publish("me/photos", FacebookType.class, BinaryAttachment.with(attachmentName, temporaryStream), Parameter.with("message", "my myssage")); 帖子按预期创建。我可以看到一条消息和消息下发布的图片
FacebookType publish = fc.publish("me/photos", FacebookType.class,
BinaryAttachment.with(attachmentName, temporaryStream),
Parameter.with("message", "my myssage"));
帖子按预期创建。我可以看到一条消息和消息下发布的图片
但当我想做同样的事情,但在一些网页上,而不是用户墙
FacebookType publish = fc.publish(pageId + "/photos", FacebookType.class,
BinaryAttachment.with(attachmentName, temporaryStream),
Parameter.with("message", "my myssage"));
帖子已经发布了,但我只能看到文本。不是照片。只有当我点击发帖日期时,才能看到这张照片。我也可以通过点击页面顶部的照片,然后点击“页面名称”的照片选项卡来访问这张照片
当我在页面上发布照片时,有没有办法将其视为文章的一部分?我终于找到了解决方案。若要将带有照片的帖子发布到带有普通“纯文本”帖子的部分,您需要将照片发布到您的墙(您的用户墙不是页面的墙),然后获取其链接,最后使用图片链接创建页面提要 以下是示例代码:
FacebookType photo = fc.publish(pageid + "/photos" , FacebookType.class,
BinaryAttachment.with(photoName, photoInputStream));
Link photoLink = fc.fetchObject(photo.getId(), Link.class);
FacebookType post = fc.publish(pageid + "/feed", FacebookType.class,
Parameter.with("message", "your message"),Parameter.with("type", "photo"),
Parameter.with("link", photoLink.getLink()));
编辑:我忘了一件事。当您以后删除帖子时,您不会删除到照片。要做到这一点,你必须手动操作。我终于找到了解决方案。若要将带有照片的帖子发布到带有普通“纯文本”帖子的部分,您需要将照片发布到您的墙(您的用户墙不是页面的墙),然后获取其链接,最后使用图片链接创建页面提要 以下是示例代码:
FacebookType photo = fc.publish(pageid + "/photos" , FacebookType.class,
BinaryAttachment.with(photoName, photoInputStream));
Link photoLink = fc.fetchObject(photo.getId(), Link.class);
FacebookType post = fc.publish(pageid + "/feed", FacebookType.class,
Parameter.with("message", "your message"),Parameter.with("type", "photo"),
Parameter.with("link", photoLink.getLink()));
编辑:我忘了一件事。当您以后删除帖子时,您不会删除到照片。要做到这一点,你必须手动操作。你的回答很有效,帮助了我无数次,但我发现我的解决方案并不需要
FacebookType post = fc.publish(pageid + "/feed", FacebookType.class,
Parameter.with("message", "your message"),Parameter.with("type", "photo"),
Parameter.with("link", photoLink.getLink()));
因为我可能会收到一个错误(我应该复制它以向您展示),但在我的情况下,photoLink.getLink()
返回null
因此,我更新的解决方案最终是
FacebookType photo = client.publish(groupId + "/photos",
FacebookType.class,
BinaryAttachment.with(imageName),
imageAsBytes,
"image/png"),
Parameter.with("message",
message));
只要我的2美分,再次感谢你的帮助
编辑
另外,在玩游戏时,我注意到,在我找到的解决方案中,我创建了一个facebook类型的photo
对象,而这个对象在任何地方都不会被使用,您只需调用在程序中进一步创建的客户机的publish方法
我的最后一堂课在下面,(我的应用程序是从电脑上拍摄一张照片,然后摆姿势到墙上)
在这个方法中,我的图像被转换成一个字节数组
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;
}
再次感谢你的帮助 你的回答很有效,帮了我无数的忙,但我找到了我不需要的解决方案
FacebookType post = fc.publish(pageid + "/feed", FacebookType.class,
Parameter.with("message", "your message"),Parameter.with("type", "photo"),
Parameter.with("link", photoLink.getLink()));
因为我可能会收到一个错误(我应该复制它以向您展示),但在我的情况下,photoLink.getLink()
返回null
因此,我更新的解决方案最终是
FacebookType photo = client.publish(groupId + "/photos",
FacebookType.class,
BinaryAttachment.with(imageName),
imageAsBytes,
"image/png"),
Parameter.with("message",
message));
只要我的2美分,再次感谢你的帮助
编辑
另外,在玩游戏时,我注意到,在我找到的解决方案中,我创建了一个facebook类型的photo
对象,而这个对象在任何地方都不会被使用,您只需调用在程序中进一步创建的客户机的publish方法
我的最后一堂课在下面,(我的应用程序是从电脑上拍摄一张照片,然后摆姿势到墙上)
在这个方法中,我的图像被转换成一个字节数组
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;
}
再次感谢你的帮助