When using the Test Console at the bottom of the stream.publish page, I can't seem to ever get it to post an "attachment" or any "action_links", even when using the examples on their own Stream Attachments page -- specifically, everything I put in the "attachment" field seems to be ignored (the entry is just posted without it) and I have yet to find anything I can put in the "action_links" field that does not result in "error JSON decoding action_links".
Can any of you make this work at all? If so, please show me an example. I'm trying:
- attachment:
{ 'href': 'https://www.dnalounge.com/flyers/2010/10/02.html', 'name': 'test', 'caption': 'test2', 'description': 'test3', 'media': [{ 'type': 'image', 'src': 'https://www.dnalounge.com/flyers/2010/10/02-1.jpg', 'href': 'https://www.dnalounge.com/flyers/2010/10/02.html' }]} action_links:
[{'name':'Google','href':'http://www.google.com/','description':'Google Home Page'}]
Update: Basically, the documentation is full of lies, including all of the examples: you have to use double-quotes around strings, not single-quotes. Single-quotes work only if you are writing your code in Javascript, but not if you are using the Test Console, Perl, or any other non-Javascript-based API that must communicate through JSON.
This is a really lame detail, but single quotes around strings aren't valid JSON. A really pedantic parser might care.
ETA: Of course, I just now clicked through to their examples, which are all invalid JSON. Awesome.
Changing all the ' to " in action_links got me a different error message, "action links must have the 'href' and 'text' attributes". Using 'href':"url" or href:"url" gets me the old "error JSON decoding action_links".
So what happens if you add a "text": "This is required" attribute?
It takes skill to produce invalid content in a format as simple as JSON.
Part of me wants to say "Have we learned nothing from Perl, to only allow one form of quoting character, and suffer endless backslashitis in some rare, but annoying, cases?" - but then, JSON is a serialisation format, and keeping it as simple as possible is probably better than making it slightly easier for humans to hand-code it.
Well, yeah, it sort of depends on what angle you come at it from. If your understanding is that JSON is just JavaScript without code, you can get pretty far until you encounter a strict parser. Even understanding that that wasn't the case, I got tripped up recently by including hex encoded numbers, as in 0x00. Valid JavaScript, and JSON.org's own json2.js library handled it without complaint. Perl's JSON library, on the other hand, barfed all over it.
Yeah, but the spec of JSON is so simple that it fits on one web page!
Also, arguably having JSON exactly resemble Javascript was a mistake, as for security reasons you'd still need to parse it for e.g. closures, evals. Being able to just eval a string you're given is tempting, but ultimately a massive security hole waiting to happen.
does the application you have selected in the console have the publish_stream permission?
If it didn't, it wouldn't be able to publish anything, right? It's publishing text to the stream, it's just omitting the attachment.
Anyway, I don't remember how to see or change the app's permissions. I fear I am about to be eaten by a Grue.
take a look at http://fbrell.com/fb.ui/stream.publish. I just ran a test and it worked for me.
It doesn't work for me when I paste text from that page into the test console. Are you able to make it work in the test console, rather than from Javascript?
no. looks like a bug in the api or docs. i'll log it. you try using the graph api? i would try but i am on an ipad. :-)
You need to wrap the JSON in quotes:
"{'name':'Google','href':'http://www.google.com/','description':'Google Home Page'}"
We'll change the doc or fix the test console to do this.
Hey, on another note, do you understand why I can't seem to get the default tab on http://www.facebook.com/dnalounge to be the "DNA Lounge" tab instead of the "Wall" tab? The "Wall settings" has "DNA Lounge" selected under "Default Landing Tab for Everyone Else", but it seems to be ignoring it (even for people who are not admins of the app.)
it is the default tab for me.
I suspect the Test Console is busted. It should/will work from real JS from a FB app. I've been using FB.ui({ method: 'stream.publish' } ...) in a FB app with great success, so I know it DOES work and what you've shown above (the attachment) looks right to me.
I got it working. There are at least two bugs in the docs: first, you can't use ' as a string-quote, you have to use ". Maybe that works in Javascript, but it doesn't work in the test console, nor does it work from Perl (where you have to pass JSON strings, not "Javascript" strings, I guess.) Second, the "to attach a link with a description, use the following example"-example on the Attachments page says "description" where it should say "text".
As for bugs in the code itself -- if you have a syntax error or other problem in "action_links", you get an error response back from stream.publish. But, if there is anything wrong at all in "attachments", it just silently ignores the error and pretends that the attachments arg wasn't passed in. That's kind of awful behavior; if I did something wrong, it should tell me...