如何使用 Facebook Java API 将附件添加到墙贴?
嘿, 我在使用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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建
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.