-1

我正在构建一个简单的在线游戏,我希望用户在完成游戏时被提示在 Facebook 上分享他们的分数。我真的不想使 UI 过于复杂,理想情况下希望它类似于 twitter 的推文按钮并具有预定义(可编辑)消息,例如:

“我刚刚在 mygame.com 上获得了 560 分”

我希望将其发布到用户的 Facebook 墙上。

代码和用户最简单的选择是什么?我正在使用 php、mysql、jquery、javascript、ajax

4

3 回答 3

0

假设您手头有 Facebook Javascript SDK,您可以构建一个链接到 的按钮https://www.facebook.com/dialog/feed?app_id=393236134020452&link=<the url you want to share>&picture=<url of any picture you want to show in the users' status updates>&name=<title of the status update>&caption=<text of the status update>&redirect_uri=<url to redirect users upon completion of the sharing action>,可能在一个新选项卡中。

如果你想看看,我在这里使用纯 JS 和 JS SDK做了类似的事情。

于 2012-09-11T14:34:32.197 回答
0

建议您使用 Javascript SDK:https ://developers.facebook.com/docs/reference/javascript/

<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : 'YOUR_APP_ID', // App ID - get one at https://developers.facebook.com/apps/
      channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      xfbml      : true  // parse XFBML
    });

    // Additional initialization code here - Change fields below to match what you want to share and wrap it inside a function that you trigger on click
    FB.ui({
      method: 'feed',
      name: 'Facebook Dialogs',
      link: 'https://developers.facebook.com/docs/reference/dialogs/',
      picture: 'http://fbrell.com/f8.jpg',
      caption: 'Reference Documentation',
      description: 'Dialogs provide a simple, consistent interface for applications to interface with users.'
    },function(response) {
      if (response && response.post_id) {
        alert('Post was published.');
      } else {
        alert('Post was not published.');
      }
    });
  };

  // Load the SDK Asynchronously
  (function(d){
     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     ref.parentNode.insertBefore(js, ref);
   }(document));
</script>

频道文件可以是:

<script src="//connect.facebook.net/en_US/all.js"></script>
于 2012-09-11T14:38:59.087 回答
0
    $attachment = array(
     'access_token' => $accessToken,
     'message' => $text,
     'name' => $appName,
     'link' => $appLink,
     'description' => "I have just scored 560 on mygame.com",
    );
    return $response = $facebook->api("/$fbid/feed", 'POST', $attachment);

其中 $facebook 是 Facebook API 对象。您必须创建 facebook 应用程序和权限才能在用户的墙上发帖。

于 2012-09-12T13:03:09.810 回答