开发者

How to use Facebook FBJS Feed Forms

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_Forms

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 $开发者_StackOverflow社区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.


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>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜