如何在不打开对话框的情况下在 Facebook 墙上发帖?

发布于 2024-12-07 22:15:10 字数 725 浏览 1 评论 0原文

我的网站上有一个测验程序,用户通过他们的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

紫﹏色ふ单纯 2024-12-14 22:15:10

这是因为 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.

生活了然无味 2024-12-14 22:15:10

您应该请求“publish_stream”权限,以便能够发布摘要故事而不向用户显示对话框。

示例代码可能如下所示:

FB.login(function(response) {
  if (response.authResponse) {
    console.log('Posting message');
    FB.api('/me', 'post', {message: 'Beware, boiling water...'});
   } else {
     console.log('User cancelled login or did not fully authorize.');
   }
 }, {scope: '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:

FB.login(function(response) {
  if (response.authResponse) {
    console.log('Posting message');
    FB.api('/me', 'post', {message: 'Beware, boiling water...'});
   } else {
     console.log('User cancelled login or did not fully authorize.');
   }
 }, {scope: 'publish_stream'});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文