Facebook Apps with Google App Engine
June 29th, 2009 - Programming
The internet's simplest introduction to writing a facebook application with Google App Engine, in Python, with Django.
So let's start with an easy introduction to writing a facebook app with app engine. First of all, you need to sign up for an application with Facebook. You can do this here, just click "set up new application" once you've added the facebook developer application, and give them your preferences. You should then come to a page full of settings, with titles like "Essential Information", and "Basic Information". Use the navigation on the left to edit the "canvas" settings. Keep this page open.
Now you must sign up for a new application with Google App Engine. That can be done here. Next, you need to write your standard app.yaml file (To illustrate the process, I'm going to be making a simple counter, to count how many times an application "canvas" is viewed). I'm going to call my application "fbstcntr" (as in "facebook stat counter") The app.yaml file is going to look like this (the stylesheets director is for you to use later when designing your canvas):
Now go back to the facebook settings page, and where it says "Canvas Callback URL", enter http://(your-application-name).appspot.com. Also, enter the name of your application in "Canvas Page URL".
Next, you'll need to make your canvas.html file (this is the one that facebook will use for your application's canvas). Mine just looks like this (remember I'm using Django, but that's by no means essential for this tutorial):
Save this file in the same folder as your app.yaml file (the folder I'm using is just called "fb"). Next, we'll make our main.py file - this is where things get slightly more complicated, but I'll keep it simple yo.
Save this file as "main.py". Next, visit this page, and save all of that code straight into a file called "facebook.py", and make sure that file is in the same folder as the rest of your application. Well done! You've just made the skeleton of your facebook application! Now, run your command prompt, and make it go to where your application is stored (its directory). For me it looks like this:
Type in "appcfg.py update " and the name of the file that is holding your application files. Fire this off and it will update your application!
Every time you visit this application's page at apps.facebook.com/your-app-name/, it will update the datastore and display the amount of visitors that have been there previously. You can grow this application more by working on your canvas.html file, and including more functions that are available with facebook.py. There are so many possibilities still for facebook apps, and now you can make them and host them for free off Google's servers - so best of luck!
PyThoughts


4 Comments