2

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!

Nate Totten
  • 8,904
  • 1
  • 35
  • 41

1 Answers1

1

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.

Marc Novakowski
  • 44,628
  • 11
  • 58
  • 63
  • As I've seen on the Graph API documentation, a Facebook Post object has a 'source' attribute. For setting this attribute I also have to use a URL of an image found on a public webserver? – Catalin Buleandra Oct 01 '10 at 07:27
  • Yes, the APIs are all based on XML-RPC under the covers and aren't designed to transfer large amounts of data to Facebook. In order to get images onto their site, they usually just have you specify an external URL so their servers can perform the download of that asset into their systems. – Marc Novakowski Oct 01 '10 at 18:42
  • on http://fbdevwiki.com/wiki/Graph:Photo it says, if you want to upload an image rather than providing a url, you would need to put a photo file attachment as multipart/form-data to the POST request. So you mean, that doesn't really work and I still need a public webserver first? Or did you only refer to AttachmentMediaImage & stream_publish? – Mathias Conradt Jan 06 '11 at 03:55
  • 1
    Yes, it appears that it would work using the Graph API you linked to - although that appears to be a pure REST-style API whereas the Java API uses the traditional XML-RPC means of communicating with their servers which doesn't support sending attachments. So to use the Graph API from Java you'd probably need to use a library such as Apache HttpClient to make the REST calls (and file attachments) yourself. – Marc Novakowski Jan 11 '11 at 19:33