这是我在我运营的 Facebook Connect 网站上使用的示例:
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);
这些FB.Connect
方法几乎与普通的 JS 方法相同,因此类似的方法应该对您有用。
我要指出的是,您将其<?php echo $message; ?>
作为呼叫的第一个参数Facebook.streamPublish()
。假设$message
是一个文本字符串,那么您需要将该输出用引号括起来,以使其成为有效的 Javascript。同样,这return attachment;
条线对我来说没有多大意义。为什么那里有退货声明?我会将您的代码更改为:
<script type="text/javascript">
var attachment = <?php echo json_encode($attachment); ?>;
Facebook.streamPublish('<?php echo addslashes($message); ?>', attachment, null, <?php echo $user; ?>);
</script>