Classic ASP and Facebook Connect

September 3, 2010

I wrote a simple Classic ASP game called Never Ending Maze back in 1998. It was in fact the first thing I wrote in ASP (VBScript) and how I learned how to program in VBScript. Anyhow in order to get facebook to interface with it I simply used the “Connect” button. Here’s how the HTML code looks:


login.asp

[html]<a href="http://www.facebook.com/login.php?v=1.0&api_key=APIKEY&next=http://www.neverendingmaze.com/fb_connect.asp"><img id="fb_login_image" src="images/Connect_with_facebook_iphone.png" alt="Connect"/></a>[/html]

After that hard bit of code was done, I wrote the simple fb_connect.asp page. This page handles the request, and communicates back to facebook to get the cookie. Once it has the cookie it will automatically redirect you to the /login.asp page. If it doesn’t get the cookie, then it will refresh the page until it finally does. Do note that if you disable third party cookies this may not work:

fb_connect.asp

[html]<%
Dim fb_uid,ApiKey
fb_uid = ""
ApiKey = "183f81e6ef8024631ed9c91feb9e0d84"
fb_uid = Request.Cookies(ApiKey & "_user")
Session("fb_uid") = fb_uid
If IsNumeric(fb_uid) And Len(fb_uid) > 2 AND Len(Request.Cookies(ApiKey & "_session_key"))>2 Then
Response.Redirect "/login.asp"
End If
%>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<head runat="server">
<title>Never Ending Maze – Loading Facebook Connect…</title>
<script>
function refresh()
{
window.location.reload();
}
setTimeout("refresh()",1700);
</script>
<meta http-equiv="refresh" content="2">
</head>
<body style="background-color:#000000;">
<form id="form1" runat="server">
<div>
<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"></script>
<script type="text/javascript">
FB.init("183f81e6ef8024631ed9c91feb9e0d84", "xd_receiver.htm");
</script>
loading …
</div>
</form>
</body>
</html>[/html]

It’s as easy as that to make a classic ASP page work with Facebook’s Connect.

+1 this post if it helped you!

2 comments on “Classic ASP and Facebook Connect

  1. reginald lycke on said:

    hey,
    Greetings from Belgium.
    i want lauch a contest where people have to like a fanpage to participate at the contest. After the like a form with the name, firstname and e-amiladress most be send to e-mailadres and stored i a accesdatabase.
    can you help with that?
    Regards
    reginald

Leave a Reply