Facebook Connect / Pass用户名到数据库进行存储


Facebook Connect / Pass User's name to database for storage

我正在使用Facebook Connect API从我的网页连接到FB,分享指定的链接,然后通过警报消息感谢他们。我缺少的是能够抓住海报的用户名并将其保存在我的数据库中。这样做的原因是因为我用它来输入每个分享链接的人参加抽奖,所以我需要跟踪谁在做这件事。

到目前为止我写的是:

 <html>
    <head>
      <title>Facebook Share Page</title>
    </head>
    <body>
      <div id="fb-root"></div>
      <script>
        window.fbAsyncInit = function() {
          FB.init({
            appId      : 'REMOVED-FOR-SECURITY',
            status     : true, 
            cookie     : true,
            xfbml      : true
          });

          FB.ui(
  {
    method: 'feed',
    name: 'I''ve Got Kids!',
    link: 'http://ivegotkids.com',
    picture: 'http://ivegotkids.com/wp-content/themes/thepink/images/logo.png',
    caption: 'Parents Supporting Parents',
    description: 'I just registered at I''ve Got Kids, a unique support site. From pregnancy to grandparenthood, there''s something for everyone. I''m sure you''ll find something on IGKs to interest you! Click the link and register for free.'
  },
  function(response) {
    if (response && response.post_id) {
      alert('Post was published.');

    } else {
      FB.api('/me', function(response) {
    alert(response.name +', Thank you for sharing. You will now be entered into our prize draw for a free lifetime membership.');
        });
    }
  }
);
        };
        (function(d){
           var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
           js = d.createElement('script'); js.id = id; js.async = true;
           js.src = "//connect.facebook.net/en_US/all.js";
           d.getElementsByTagName('head')[0].appendChild(js);
         }(document));
      </script>
    </body>
 </html>

我在最后一步中切换了警报,仅用于测试目的,因为我不想在测试时向我的墙上发布100次内容,因此消息目前仅在帖子被取消而不是发送时输出。

我现在需要做的是抓住海报的用户名并将其保存在我的数据库中。我可以通过使用FB获取用户名。API调用,就像我最后在警报中做的那样但我不知道如何将这个传递到数据库。

任何帮助都会很感激。

谢谢!

因为要用javascript收集数据,所以需要使用AJAX调用来保存数据。一种方法是创建一个可以保存数据的页面,并让javascript将数据发送到该文件。

看看我博客上的AJAX帖子,看看我是怎么做的。http://sullivan.net/blog/tag/ajax/