如何使用 Facebook Java API 将附件添加到墙贴?

发布于 2024-09-25 19:47:31 字数 1725 浏览 2 评论 0原文

嘿, 我在使用stream_publish方法时遇到了一些麻烦,更确切地说是我想要包含的附件​​。 我正在构建一个桌面应用程序,我希望能够在用户墙上发布。该帖子将包含一条消息和一张我将从本地硬盘上传的照片。问题是我不知道如何指定附件的源属性。这是一个代码片段:

Attachment attachment = new Attachment();
AttachmentMedia media = new AttachmentMediaImage("file:/c:/picture.png", "file:/c:/picture.png");
attachment.addMedia(media);
facebook.stream_publish("picture", attachment, null, new Long(xxxxxxxL), null);

我根本不知道如何构造 AttachmentMediaImage 对象。我不断收到以下异常:

com.google.code.facebookapi.FacebookException: One or more of your image records failed to include a valid 'href' field.
    at com.google.code.facebookapi.JsonHelper.parseCallResult(JsonHelper.java:59)
    at com.google.code.facebookapi.ExtensibleClient.extractString(ExtensibleClient.java:2296)
    at com.google.code.facebookapi.ExtensibleClient.stream_publish(ExtensibleClient.java:2150)
    at com.google.code.facebookapi.SpecificReturnTypeAdapter.stream_publish(SpecificReturnTypeAdapter.java:503)
    at MainWindow$1.titleChange(MainWindow.java:64)
    at org.jdesktop.jdic.browser.WebBrowser.dispatchWebBrowserEvent(Unknown Source)
    at org.jdesktop.jdic.browser.NativeEventThread$2.run(Unknown Source)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

任何帮助将不胜感激。谢谢!

Hey,
I have some trouble using the stream_publish method, more exactly with the attachment I want to include.
I am building a desktop application and I want to be able to post on a user's wall. The post will include a message and a photo I will upload from my local HDD. The problem is I don't know how to specify the source attribute of the attachment. Here is a code snippet:

Attachment attachment = new Attachment();
AttachmentMedia media = new AttachmentMediaImage("file:/c:/picture.png", "file:/c:/picture.png");
attachment.addMedia(media);
facebook.stream_publish("picture", attachment, null, new Long(xxxxxxxL), null);

I simply can't figure out how to construct the AttachmentMediaImage object. I keep getting the following exception:

com.google.code.facebookapi.FacebookException: One or more of your image records failed to include a valid 'href' field.
    at com.google.code.facebookapi.JsonHelper.parseCallResult(JsonHelper.java:59)
    at com.google.code.facebookapi.ExtensibleClient.extractString(ExtensibleClient.java:2296)
    at com.google.code.facebookapi.ExtensibleClient.stream_publish(ExtensibleClient.java:2150)
    at com.google.code.facebookapi.SpecificReturnTypeAdapter.stream_publish(SpecificReturnTypeAdapter.java:503)
    at MainWindow$1.titleChange(MainWindow.java:64)
    at org.jdesktop.jdic.browser.WebBrowser.dispatchWebBrowserEvent(Unknown Source)
    at org.jdesktop.jdic.browser.NativeEventThread$2.run(Unknown Source)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

Any help will be appreciated. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽清梦 2024-10-02 19:47:31

创建 AttachmentMediaImage 时,您需要使用公共网络服务器上图像的 URL - 您无法使用此 API 上传本地图像。

When creating the AttachmentMediaImage you need to use a URL of an image on a public webserver - you can't upload a local image using this API.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文