自定义Facebook连接按钮 [英] Custom facebook connect button

查看:144
本文介绍了自定义Facebook连接按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何用自己的自定义替换生成的Facebook登录按钮?



我猜测它可以通过创建一个触发代码的函数来完成在对话框中或通过一些CSS技巧将屏幕上的按钮驱动。我更喜欢第一个解决方案。



我如何使自己的按钮做他们的工作,摆脱默认按钮?



以下是Facebook开发人员网站的示例代码:





  require'fb / facebook .PHP'; 

$ facebook = new Facebook(array(
'appId'=>'X',
'secret'=>'X',
)) ;

//查看是否有来自cookie的用户
$ user = $ facebook-> getUser();

if($ user){
try {
//继续知道你有一个登录的用户被认证。
$ user_profile = $ facebook-> api('/ me');
} catch(FacebookApiException $ e){
echo'< pre>'。htmlspecialchars(print_r($ e,true))。'< / pre>
$ user = null;
}
}

?>
<!DOCTYPE html>
< html xmlns:fb =http://www.facebook.com/2008/fbml>
< body>
<?php if($ user){?>
您的用户个人资料是
< pre>
<?php print htmlspecialchars(print_r($ user_profile,true))?>
< / pre>
<?php} else {?>
< fb:login-button>< / fb:login-button>
<?php}?>
< div id =fb-root>< / div>
< script>
window.fbAsyncInit = function(){
FB.init({
appId:'<?php echo $ facebook-> getAppID()?>',
cookie:true,
xfbml:true,
oauth:true
});
FB.Event.subscribe('auth.login',function(response){
window.location.reload();
});
FB.Event.subscribe('auth.logout',function(response){
window.location.reload();
});
};

(function(){
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root')。appendChild(e);
}());

< / script>
< / body>
< / html>


解决方案

只需使用JavaScript SDK的FB.login方法,并在你自己的按钮上点击它。



http://developers.facebook.com/docs/reference/javascript/FB.login/


How would I replace the generated facebook login button with my own custom one?

I am guessing it can either be done by creating a function of the code that fires up the dialog or driving the button off the screen with some css tricks. I'd prefer the first solution.

How could I make my own button do what theirs does and get rid of the the default button?

Here's the example code from the facebook developers site:

require 'fb/facebook.php';

$facebook = new Facebook(array(
  'appId'  => 'X',
  'secret' => 'X',
));

// See if there is a user from a cookie
$user = $facebook->getUser();

if ($user) {
  try {
    // Proceed knowing you have a logged in user who's authenticated.
    $user_profile = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    echo '<pre>'.htmlspecialchars(print_r($e, true)).'</pre>';
    $user = null;
  }
}

?>
<!DOCTYPE html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
  <body>
    <?php if ($user) { ?>
      Your user profile is
      <pre>
        <?php print htmlspecialchars(print_r($user_profile, true)) ?>
      </pre>
    <?php } else { ?>
      <fb:login-button></fb:login-button>
    <?php } ?>
    <div id="fb-root"></div>
    <script>
      window.fbAsyncInit = function() {
        FB.init({
          appId: '<?php echo $facebook->getAppID() ?>',
          cookie: true,
          xfbml: true,
          oauth: true
        });
        FB.Event.subscribe('auth.login', function(response) {
          window.location.reload();
        });
        FB.Event.subscribe('auth.logout', function(response) {
          window.location.reload();
        });
      };

      (function() {
        var e = document.createElement('script'); e.async = true;
        e.src = document.location.protocol +
          '//connect.facebook.net/en_US/all.js';
        document.getElementById('fb-root').appendChild(e);
      }());

    </script>
  </body>
</html>

解决方案

Just use FB.login method of the JavaScript SDK, and call it onclick on your own button.

http://developers.facebook.com/docs/reference/javascript/FB.login/

这篇关于自定义Facebook连接按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆