views:

1507

answers:

2

I'm trying to call a Feed Form in my Facebook application and I'm not sure how to do so. I'm not familiar with the FBJS and its API. Specifically I need the following dialogue to show up: http://wiki.developers.facebook.com/index.php/Feed%5FForms

Here's what I got for now:

<script type="text/javascript">
var attachment = <?php echo json_encode($attachment); ?>;
return attachment;
Facebook.streamPublish(<?php echo $message; ?>, attachment, null, <?php echo $user; ?>);
</script>

Is there anything else I need to do in order to properly call a Feed form? A code example would help me a lot if anyone is willing to write one up.

+2  A: 

Here's an example I use from a Facebook Connect site that I operate:

var message = 'This is my message!';
var attachment = {
    'name':'Page name',
    'href':'http://mysite.com',
    'caption':'Some kind of caption';
};
attachment.media = [{'type':'image','src':'http://mysite.com/images/lolcat.jpg','href':'http://mysite.com'}];
var action_links = [{'text':'Action Link!','href':'http://mysite.com'}];
FB.Connect.streamPublish(message, attachment, action_links);

The FB.Connect methods are almost identical to the normal JS methods, so something similar should be working for you.

I would point out that you have <?php echo $message; ?> as the first parameter to your Facebook.streamPublish() call. Assuming $message is a text string, then you need to wrap that output in quotes in order for it to be valid Javascript. As well, the return attachment; line doesn't make much sense to me. Why is there a return statement there? I would change your code to this:

<script type="text/javascript">
var attachment = <?php echo json_encode($attachment); ?>;
Facebook.streamPublish('<?php echo addslashes($message); ?>', attachment, null, <?php echo $user; ?>);
</script>
zombat
Sorry about that, I meant to put that there to see if anything would pop up. I've tried the following code that you've posted and it doesn't seem to even bring up the Feed Form at all.
Steven Lu
Hmm... well you'd have to change my code to use `Facebook.streamPublish` rather than `FB.Connect.streamPublish`. However, if yours isn't working, I'd double check that you have a valid facebook session, and that the FBJS libraries are loaded. Are you getting any kind of Javascript errors?
zombat
Unfortunately, I'm not getting any errors whatsoever. And I've modified your code a little too. It could be that `json_encode()` isn't properly creating the JSON array. I'll make the attachment into the form you have listed above to see if it works. Also, is it just that in FBML you don't get Javascript errors?
Steven Lu
Ah, you're using FBJS, that makes more sense to me now. I'm always stuck in iframe-app land, so I was making assumptions. Yeah, it's tough to debug FBJS, you probably won't see any errors from it. What happens if you just try 'Facebook.streamPublish();' with no parameters? That should theoretically pop up a feed box that just prompts you to change your status message.
zombat
Unfortunately, nothing happens. Note that this is my first time ever using the FBJS API so I have no idea if I need to initialize the API or anything. I've been reading up on some other articles where I need like `FB.Facebook.init("APIKEY", "channel/xd_receiver.htm");`. Can you help provide me like how to call and initialize the FBJS API library and such to do the stream_publish call?
Steven Lu
You shouldn't need to use anything involving `xd_receiver.htm` I wouldn't think. That's for cross-domain communication for Facebook Connect sites and iframe applications. Unfortunately I can't say as I've ever used streamPublish() from an FBML app before, and I don't have access to my test apps at the moment. I can run a couple of tests tomorrow possibly, but you might have it figured out by then.
zombat
Wow, this is pathetic. I just found the Java debug utility to find out that `Facebook.streamPublish();` is all I need to call. The rest of my code has syntax errors apparently. Thanks for all your help zombat, I'll post my solution when it is available!
Steven Lu
+1  A: 

For FBML canvas pages, all you need to do is execute the command as follows:

<script type="text/javascript">

var attachment = <?php echo json_encode($attachment); ?>;

Facebook.streamPublish('', attachment, null);       

</script>

That should easily bring up the Feed Form.

Steven Lu
My bad, there's updated it now cause there was a syntax issue.
Steven Lu

related questions