如果您想使用 Javascript api 获取已签名的请求,您可以使用它FB.getLoginStatus()
来检索已签名的请求。也就是说,如果用户登录到您的应用程序/网站。如果没有,您可以调用 FB.login 方法。我试过这个方法:
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({ appId: 'YOUR_APP_ID', //change the appId to your appId
status: true,
cookie: true,
xfbml: true,
oauth: true});
function updateButton(response) {
console.log(response);
if(response.status == 'connected'){
//alert('Yes Connected');
console.log(response.authResponse.signedRequest);
//This log can be seen through the firebug extention in console tab
}
else{
alert('Not Connected');
}
}
// run once with current status and whenever the status changes
FB.getLoginStatus(updateButton);
};
(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>