Introduction
Hello
again. If you have read my previous article about creating an application
for Facebook, you most probably have noticed that the application sample might
not be working anymore. Why? Well, because that application was built on the REST
API, which is being deprecated by Facebook and replaced by the GraphAPI
framework. Not to worry, this is the exact purpose of this article, and when
Facebook changes their framework again, we’ll cross that bridge when or if we
get there.
GraphAPI
First, let
me explain how the GraphAPI works, and what it is precisely. The GraphAPI
is actually a lot less complicated than one would think. It uses the very
same principle programmers use every day, and that is: everything is connected,
and everything has properties and / or methods. For example, each event in Facebook
has certain properties, each friend has certain properties and methods.
Everything is connected, but how? Very simple. Let us assume I Like a certain
page. Then, somebody else also Likes that page. Right, now we have 2 people who
share a common interest. Let us take it a step further. Because we have Liked
the same page, we are now connected. We’ll be able to see which friends each
person has, we will see their Likes, and so on. So everything is connected, via
a certain relationship that has been formed. Have a look at how Facebook
explains their GraphAPI
FQL
Facebook Query
Language
uses a similar style to SQL to extract the correct information from the correct
tables. Anything you see on Facebook forms part of a database. It is broken down into several
separate tables. For example: Friends is a table, Friend Request is a table,
Messages is a table, Notifications is a table, Like is a table and so on. For a
complete list of available tables, have a look here. The above tables I mentioned
might have different names, as I was just using them to illustrate my example
better. We will use FQL to extract the information we need in our sample
application.
Sample
I was lucky
enough to stumble upon CodePlex some time ago.
It is an excellent site and it gets better day by day. On CodePlex they
provide an SDK for Facebook. An SDK
is a software development kit, which provides samples and tutorials on a
certain topic. The sad thing here is that the Facebook SDK they provide is
strictly for C#.
Sometimes I wonder if people do not realize how powerful VB.NET is, or if
they just don’t care. I love C# and VB equally, and I always try to make the
same things in both languages, just to prove that it is possible. I had an extensive
look at the sample they have provided and was quite happy with them. I then had
the brainwave to make my own Notifier application with VB.NET. I
had two choices, use a C# / VB.NET
converter, or convert it manually. I chose the hard option, which was to
convert the codes manually. Now, do not get me wrong, this is not a verbatim
copy of one of CodePlex’s samples. Yes, I do things similar, because that is
the only way, but I do make use of my own logic as well.
Because I
chose to convert the code manually, I encountered a lot of issues, and had to
improvise, and rewrite certain segments completely. With the sample that I am
providing, I aim to first show you that Facebook applications can be done in
VB.NET, and second to provide the ability for lazy people, such as myself, to
check notifications from Facebook on my profile, thus eliminating the need to
open my Internet browser and navigating to my Facebook profile page.
Setup
The first
step is actually optional for this article, but I would really recommend it–that
is if you really want to learn the complete ins and outs of creating a Facebook
application. The first step is to download the SDK from
CodePlex. This will give you access to all the needed DLL files inside
their associated projects. Once downloaded, the samples folder will be
named something in the lines of facebooksdk_b3789011d8e2Samples; inside
there you will find all of the various samples provided. Have a look at a
sample named CSWinFormsAuthTool. This is the base from which I will be
working. What’s important here is the fact that it gives you the Facebook.dll
and the Newtonsoft.Json.dll, which we will use in our application.
The second
step is to think of a proper name for your application, and then let Facebook
know that you intend to make a program. Without setting your application up on
Facebook, you will not get an AppID nor an App Secret. You will
need these if you intend to develop your application further inside Visual Studio. We
will be using Visual Studio 2010 for this example. Once you have a funky name,
you will need to go to the Developers section of Facebook. At the bottom of
your Facebook page, there will be a link entitled Developer. Go there.
You may be asked to install the Developer Application as well. Once you
have done that, you will see that Facebook has given you access to
Documentations, Samples, Forums and the Application Directory. Good, we’re
halfway there.