views:

99

answers:

1

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!

A: 

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
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?
catalinb
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