2013-02-25 2 views
0

Как я могу вызвать функцию, когда Facebook был аутсорсирован? Мне нужно передать его на другую страницу, основанную на успехе. Если это разрешено, я хочу переслать его на новый jsp. Как я могу назвать эту функцию? Я прочитал, что через Fb.ui мы можем написать функцию обратного вызова. Но как будет называться FB.ui? Я пытался, но как позвонить в FB.ui?Как я могу вызвать функцию, когда Facebook был аутсорсирован? Не удалось позвонить FB.ui

ответ

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 */ 
    } 
} 

В зависимости от ваших потребностей, вы можете слушать других AUTH связанных событий - см facebook docs для подписки на мероприятия здесь: http://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/