8

我正在使用 facebook open graph,新的 api,我可以这样做:

<fb:login-button show-faces="true" max-rows="9" perms="email" autologoutlink="true" onlogin="window.location = 'http://www.example.com/facebook/facebook_test/'"></fb:login-button>

但是当我阅读文档时,如果我需要更多选项http://developers.facebook.com/docs/reference/javascript/FB.login说我可以:

FB.login(function(response) {
  if (response.session) {
    if (response.perms) {
      // user is logged in and granted some permissions.
      // perms is a comma separated list of granted permissions
    } else {
      // user is logged in, but did not grant any permissions
    }
  } else {
    // user is not logged in
  }
}, {perms:'read_stream,publish_stream,offline_access'});

但是,如果我需要另一个图像作为 fb 按钮,并且如果我需要其他东西,我无法找到如何做到这一点,我可以在 html 的哪个部分调用 FB.login,在标签“脚本”之间?

4

1 回答 1

30

为此,您需要使用Javascript SDK。只需将其包装FB.login到某个函数中并在您想要的任何地方调用它。例如,如果您想在图像单击时调用它:

<html>
    <head>
    </head>
    <body>
        <div id="fb-root"></div>
        <script>
          //initializing API
          window.fbAsyncInit = function() {
            FB.init({appId: 'your app id', status: true, cookie: true,
                     xfbml: true});
          };
          (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>

        <!-- custom login button -->
        <a href="#" onclick="fblogin();return false;"><img src="images/my_login.png"></a>


        <script>
          //your fb login function
          function fblogin() {
            FB.login(function(response) {
              //...
            }, {scope:'read_stream,publish_stream,offline_access'});
          }
        </script>

    </body>
</html>
于 2010-09-14T15:28:29.640 回答