如何在不打开对话框的情况下在 Facebook 墙上发帖?
我的网站上有一个测验程序,用户通过他们的 Facebook 帐户登录并玩测验。
成功完成测验后,我想将他们的分数和排名发布在他们的墙上。 Facebook 登录和注销工作正常。如何在不显示对话框的情况下在墙上显示他们的分数和排名?
我正在使用此代码在用户墙上发布分数和排名 -
require 'src/facebook.php';
<?php
$facebook = new Facebook(array(
'appId' => 'APP ID',
'secret' => 'SECRET KEY',
));
?>
<script>
FB.init({
appId:'APP ID', cookie:true,
status:true, xfbml:true
});
FB.ui({ method: 'feed',
message: '<?php echo "My score is ".$myscore." and rank is ".$rank; ?>'});
</script>
此代码为我打开一个对话框,但输入字段为空。如果用户单击“发布”按钮,那么他们的墙上不会发布任何内容,如果他们编辑输入字段中的文本,那么他们将发布错误的信息。该字段应该是不可编辑的,或者该框不应该存在。
请通过代码示例向我建议一个解决方案。
I'am having a quiz program on my site where user logs in through their facebook account and play the quiz.
After successfully completing the quiz I want to post their score and rank on their wall. Facebook login and logout is working fine. How do I show their score and rank on their wall without displaying a dialog box?
I'm using this code to post the score and rank on user's wall-
require 'src/facebook.php';
<?php
$facebook = new Facebook(array(
'appId' => 'APP ID',
'secret' => 'SECRET KEY',
));
?>
<script>
FB.init({
appId:'APP ID', cookie:true,
status:true, xfbml:true
});
FB.ui({ method: 'feed',
message: '<?php echo "My score is ".$myscore." and rank is ".$rank; ?>'});
</script>
This code is opening a dialog box for me but that is with empty input field. If user will hust click on 'Publish' button then nothing will be posted on their wall and if they edit the text in input field then they will post wrong information. Either this field should be un editable or this box should not be there.
Please suggest me a solution with code example.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是因为 FB 不允许预编辑消息字段。如果您想在用户的留言墙上发布某些内容,您应该拥有该用户的“publish_stream”权限,这样您就可以发布消息,而无需请求用户在消息框中输入内容或按“发布”按钮。但为此你必须调用 FB.api 来访问 Graph API 来访问用户的 Wall。有关更多详细信息,请参阅Graph API。
添加到您编写的此代码中,您应该通过将“oauth: true”添加到 FB.init 参数来使用 OAuth2 方法。
That's because FB not allowing pre-editing the message field. If you want to publish something in the user's Wall, you should have 'publish_stream' permission from the user, that way you will be able to post messages without requesting the user to enter something in it's message box or pressing the Publish button. But for this you have to call FB.api to access Graph API to access the user's Wall. For more details, see Graph API.
Adding to this code you wrote, you should use OAuth2 methods by adding 'oauth: true' to the FB.init parameter.
您应该请求“publish_stream”权限,以便能够发布摘要故事而不向用户显示对话框。
示例代码可能如下所示:
You should request "publish_stream" permissions to be able to publish Feed Stories without showing dialog to user.
Sample code may look like this: