Javascript apiを使用して署名されたリクエストを取得する場合FB.getLoginStatus()
は、signed_requestを取得するためにそれを行うことができます。これは、ユーザーがアプリ/ウェブサイトにログインしている場合です。ログインしていない場合は、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>