0

当 Facebook 已被授权时,我如何调用函数?我需要根据成功将它传递到另一个页面。如果它被授权,我想将它转发到新的 jsp。我怎样才能调用该函数?我通过 Fb.ui 读到我们可以编写回调函数。但是 FB.ui 将如何被调用呢?我试过但是如何调用FB.ui?

4

1 回答 1

0

在 FB.init 之后添加事件监听器

<div id="fb-root"></div>
<script>
  FB.init({
      appId      : 'YOUR_APP_ID', // App ID from the App Dashboard
      channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File for x-domain communication
      status     : true, // check the login status upon init?
      cookie     : true, // set sessions cookies to allow your server to access the session?
      xfbml      : true  // parse XFBML tags on this page?
    });

  FB.Event.subscribe('auth.login', function(response) {
      alert('The status of the session is: ' + response.status);
      window.location.replace('http://www.NEW_URL.COM/');
  });
});

传入的响应对象将包含:

{
  status: "",         /* Current status of the session */
  authResponse: {          /* Information about the current session */
    userID: ""          /* String representing the current user's ID */
    signedRequest: "",  /* String with the current signedRequest */
    expiresIn: "",      /* UNIX time when the session expires */
    accessToken: "",    /* Access token of the user */
  }
}

根据您的要求,您可以收听其他与身份验证相关的事件 - 请参阅 facebook 开发人员文档以在此处订阅事件:http: //developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/

于 2013-02-25T19:56:29.507 回答