检查用户机是否可以访问Facebook [英] Check if user machine can access Facebook

查看:161
本文介绍了检查用户机是否可以访问Facebook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Facebook在我们国家被禁止。不过,仍有大量用户可以随时使用Facebook。当然,还有很多人不能。我的网站使用Facebook像按钮和盒子。如果用户机器无法访问Facebook,页面上将会出现一些丑的部分,应该有Facebook插件。



有谁知道如何解决这个问题?我的意思是如何检查用户机器是否可以访问Facebook?

解决方案

我通过使用Facebook API设法实现了这一点。只需启动一个查询,并调用FB.XFBML.parse();当查询完成时。

 < script type =text / javascript> 
window.fbAsyncInit = function(){
FB.init({
appId:'app id',
status:false,
cookie:true,
xfbml:false,
oauth:false
});
FB.api({
method:'fql.query',
query:'SELECT uid,name FROM user WHERE uid = 1234'
},
function (response){
if(response [0] .uid =='1234'){//现在用户可以连接到Facebook
FB.XFBML.parse();
}
});
};
(function(){
var e = document.createElement('script');
e.src = document.location.protocol +'//connect.facebook.net/en_US/ all.js';
e.async = true;
document.getElementById('fb-root')。appendChild(e);
}());
< / script>


Facebook is banned in our country. However there are still a considerable amount of users who can work around to use Facebook. Of course, many others can't. My site uses Facebook like button and like box. If the user machine cannot access Facebook, there will be some "ugly" parts on the page, where there should be Facebook plugin.

Does anyone know how to resolve this issue? I mean how to check if the user machine can access Facebook? Any trick is appreciated.

解决方案

I managed to achieve this by using Facebook API. Just initiate a query, and call FB.XFBML.parse(); when the query completes.

<script type="text/javascript"> 
 window.fbAsyncInit = function () {
 FB.init({
 appId: 'app id',
 status: false,
 cookie: true,
 xfbml: false,
 oauth: false
 });
 FB.api({
 method: 'fql.query',
 query: 'SELECT uid,name FROM user WHERE uid=1234'
 },
 function (response) {
 if (response[0].uid == '1234') { // Now that the user can connect to facebook
 FB.XFBML.parse();
 }
 });
 };
 (function() {
 var e = document.createElement('script');
 e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
 e.async = true;
 document.getElementById('fb-root').appendChild(e);
 }()); 
</script> 

这篇关于检查用户机是否可以访问Facebook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆