#52WeeksOfCode Week 21 – Facebook API

Week: 21

Language: Facebook API

IDE(s): TextWrangler with MAMP

History (Official):

(From Facebook’s Facebook page)

“Founded in 2004, Facebook’s mission is to give people the power to share and make the world more open and connected. People use Facebook to stay connected with friends and family, to discover what’s going on in the world, and to share and express what matters to them.”

History (Real):

Letting us connect with friends and family and all of the other sharing and caring doesn’t pay the bills.

Facebook makes money by selling the attention of its users.  If that’s a problem for you, don’t get an account.

That’s pretty much all I have to say about that.

Discussion:

Officially, Facebook provides SDKs (Software Development Kits) for IOS, Android, Javascript and PHP. There are also third-party providers that offer support for other languages such as Objective-C, Java, Ruby, Python and Flash. Facebook does not offer support for these third-party kits.

I like to keep things simple, so I’ll be using the Facebook Javascript SDK. There is no software to download or install. You simply need to add a short section of code to your Web page. When the page is loaded into a browser, the Facebook SDK will automatically load itself.

First I need to get Facebook to recognize me as a developer. I select Register as a Developer from the Apps menu on http://developers.facebook.com (after logging in with my Facebook account). I’m asked to re-enter my Facebook password.

FB Password Verification

Password Verification

I agree to Facebook’s policies.

FB Policy acceptance

Facebook Policy Acceptance Dialogue

I’m asked to confirm my registration by entering a code that will be sent to my phone by either a text message or a phone call. Facebook seems to be unable to text to my phone for some reason, so I picked Send via Phone Call. In a few moments, my phone rang and a friendly automated voice told me my code.

Account Verification Code

Account Verification Code

Finally I was successfully enrolled as a Facebook developer. I haven’t written a lick of code yet but I still feel like I’ve accomplished something.

Now I need to get an ID and secret token for my app. These identify my software to Facebook so they can manage what I can and can’t do and also keeps other developers from pretending to be me. (Twitter and other social networking services have similar methods.)

After a couple of false starts (my app title contained a trade name, which is verboten), I was sent to a page which provided the Javascript code (whichincluded my app ID and secret token) to insert in my Web page to load and initialize the Facebook API.

I created a page called fb_test.html and saved it in my MAMP local site folder. I inserted a bit of code to add a Like button on the page, loaded it up and it worked!

Testing the Like Button

Like Button Test Successful!

So far, so good. Now I’d like to send a message to Facebook from my page. I replaced the Like button code with the code for a Send button. A quick page reload later and voila:

Send Button Load

Loading the Send Button

Now to compose a message to myself:

Composing a Send

Just saying hi….

Meanwhile, over on my Facebook account:

Message received

Hey! I got a message!

Overall, it was a very pleasant experience. Granted, I wasn’t doing anything complicated, but I appreciated the hand-holding. Sample code was easy to find and worked first time. The documentation was readily available and easy to browse.

I almost hate to say it, but this was probably the most pleasant developer experience I’ve had to date. Whatever your opinion of Facebook, and everyone’s got an opinion, I can’t fault them here.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s