使用 FB.login 登录时,response.authResponse 不包含 ID、admin、like 的 page 属性。
但是,如果我们在 PHP 中加载页面,它确实会将其包含在签名请求 (getSignedRequest) 中。
我认为它使用 javascript 可以正常工作。
问题是,如果您主要开发一个 javascript 应用程序,那么除非您使用服务器,否则您将无法检测到该页面。使用 javascript 登录后需要刷新,以便服务器可以解析签名的请求。
有任何想法吗?
使用 FB.login 登录时,response.authResponse 不包含 ID、admin、like 的 page 属性。
但是,如果我们在 PHP 中加载页面,它确实会将其包含在签名请求 (getSignedRequest) 中。
我认为它使用 javascript 可以正常工作。
问题是,如果您主要开发一个 javascript 应用程序,那么除非您使用服务器,否则您将无法检测到该页面。使用 javascript 登录后需要刷新,以便服务器可以解析签名的请求。
有任何想法吗?
使用 javascript 登录后需要刷新,以便服务器可以解析签名的请求。
不一定是“刷新”——AJAX 请求也可以。
有任何想法吗?
如果在您的情况下往返服务器不可行,您还可以在客户端解析签名的请求 - 对于 base64 解码,现代浏览器知道该方法window.atob,而对于旧浏览器,您可以从 Web 获取脚本来执行此操作。不过,这只是对签名的请求进行解码,而没有实际验证它。如果您也需要这样做,则必须使用服务器端方法,因为这需要您的应用程序密码。
如果您想使用 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>
Can't be done. Facebook only sends the page tab info to the server as part of the signed request get variable.