最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - How to detect programmatically if the user proxy is blocking access to Facebook - Stack Overflow

programmeradmin1浏览0评论

We are developing a web app () which use both FB Graph api server side, FB Javascript SDK and social plugins.

The integration with FB is deep and we would like to detect when a user visiting our website is behind a proxy which block all traffic to Facebook properties (like in some working place).

If we could detect he is blocked we could give him/her some hints, help, explanation and some alternative methods to login and interact with the application.

But I can't figure out how to do that.

I guess, but is just my guess, there's a way to detect if the user access to Facebook is blocked checking something in the Javascript SDK, but I have not been able to find out what and/or how.

Any idea?

We are developing a web app (http://beta.dammela.it) which use both FB Graph api server side, FB Javascript SDK and social plugins.

The integration with FB is deep and we would like to detect when a user visiting our website is behind a proxy which block all traffic to Facebook properties (like in some working place).

If we could detect he is blocked we could give him/her some hints, help, explanation and some alternative methods to login and interact with the application.

But I can't figure out how to do that.

I guess, but is just my guess, there's a way to detect if the user access to Facebook is blocked checking something in the Javascript SDK, but I have not been able to find out what and/or how.

Any idea?

Share Improve this question edited Apr 26, 2011 at 14:15 Max Favilli asked Apr 26, 2011 at 12:32 Max FavilliMax Favilli 6,4593 gold badges43 silver badges64 bronze badges 1
  • 1 If facebook is blocked then you can't load the Javascript SDK. I would avoid using js because of cross domain issues. Some firewalls redirect to alternate page, so you can't check if www.facebook. exists, you need to check the contents returned from facebook., however there is no guarantee which facebook page you are going to get, whether the login page or something else. – DannyKK Commented Apr 26, 2011 at 12:44
Add a ment  | 

5 Answers 5

Reset to default 7

Explaination:
We try to download the facebook favicon. If it throws an error then we know that facebook is blocked.
Note: When a proxy blocks a URL then it return an error in 4xx range back to the client.

Code:

var img = new Image();
img.onerror = function () {
 alert("It seems Facebook is blocked!"); 
}
img.src = "http://facebook./favicon.ico";

You can try this out here.

Update: Replaced server-side C# code with client-side JavaScript.

My suggestions would be since you're loading the Facebook JS SDK is to look at using the dynamic script loading capabilities that are in libaries on the web (I think Closure from Google has it built in) and attempt to dynamically load the SDK.

At this point you should be able to either A. catch an error from the attempt, or B. interrogate whether the script loaded successfully (either by methods provided by the framework or just by invoking a SDK action and checking whether you get some kind of undefined error).

If you can't load the SDK that implies something catastrophic happened.

Whether it was FB moving the location of the JS file or that the user is proxied and blocked (or even FB could be down I suppose).

Make your program visit "http://www.facebook./" and see if you get a similar source code to that one can find on the current home page. If you can, then there is no blocking Facebook or else it is! :D

I think tрe most appropriate way would be to create special test page on which you can output some test data throught fb api and two button similar "I can see data" "There is no data on page". Depending on the user's answer you may give him/her a tip or continue to work

try to insert this into your html code:

<strong>
<div class="fblikebutton_button" style="float: ; margin-left: 10px;">
   <iframe src="Delphi%20Certification%20Beta%20Program%20_%20Andreano%20Lanusse%20Blog%20_%20Technology%20and%20Software%20Development_files/like_002.htm" allowtransparency="true" style="border: medium none; overflow: hidden; width: 450px; height: 26px;" scrolling="no" frameborder="0"></iframe>
</div>
</strong>



<div class="fblikebutton_button" style="float: ; margin-left: 10px;">
<iframe src="Delphi%20Certification%20Beta%20Program%20_%20Andreano%20Lanusse%20Blog%20_%20Technology%20and%20Software%20Development_files/like_002.htm" allowtransparency="true" style="border: medium none; overflow: hidden; width: 450px; height: 26px;" scrolling="no" frameborder="0"></iframe>
</div>
发布评论

评论列表(0)

  1. 暂无评论