How to detect programmatically if the user proxy is blocking access to Facebook
We are developing a web app (http://beta.dammela.it) which use both FB Graph api server side, FB Javascript SDK and social pl开发者_如何学Pythonugins.
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?
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.com/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.com/" 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>
精彩评论