Building Facebook apps? Good luck…

18 05 2008

They’re annoying, they’re mystical, and they inspire a false sense of self-confidence like no other. They’re Facebook apps. You look at them and go, yeah, I could do that. Or, you get so overwhelmed you don’t even want to try. I decided to keep my expectations low (a smart strategy I’m finding) and see if I can do sappshotomething very basic and no-frills. The happy medium between changing the world and doing nothing.

I got a self-hosted Facebook app working, shown at left, and it is totally functional even though I am/was using PHP4 on my server space and Facebook generally requires PHP5. It’s a sample app that Facebook provides, but it was a big step for me. Here, I’m going to outline the process that I went through to get started building Facebook apps.

GoDaddy server space is a little unique in the way it’s set up and the way that Facebook apps interact with it. I’m still in the process of reconfiguring my space, and I’m also encountering a technical problem accessing phpMyAdmin (WYSIWYG MySQL database manager, as opposed to command-line) so development is limited to non-database projects at this point. The techie ticket is out and hopefully they’ll fix it soon…

developer pageBefore you do anything, join Facebook and get the Developer app on your profile. Make a new application and fill out the minimum of forms. This will get you an application key and a secret, which you’ll need to do anything. This is also where you can get sample code and link your external program to Facebook once you’ve got something to test. The apps usually won’t work outside Facebook. You can also set up a test profile (follow the guidelines) and find information on the Developers Wiki. Here’s a page that goes into more detail.

So if you want to get started doing the bare minimum things that I am doing, here is an outline of what I did:

  • Make sure you have a Web host set up. GoDaddy is the most ubiquitous. The server should be PHP-compatible. On GoDaddy, make sure you have a Linux server and NOT a Windows server.
  • Make sure you have MySQL database capability on your Web host (or on your computer if you’re developing on your own space) although this is not necessarily needed for all programs, such as the first example that I ran. You will need it to do more advanced things, however, that require file I/O.
  • Find out what version of PHP you are running and upgrade if necessary. PHP5 is preferable. PHP4 can be worked with, but requires an extension. I built my first app in PHP4 but am upgrading to PHP5 now for simplicity’s sake.
  • If you have GoDaddy, make sure you’re aware of what upgrade level you’re on. I just switched from v. 1.0 to 2.0. In the latter case, I plan to run some tests and then edit my .htaccess file to ensure that PHP5 is the default, rather than PHP4. GoDaddy can run both versions concurrently, and this has caused problems for some Facebook developers.
  • Obtain good FTP software, which is a fairly obvious point. I’m using Classic FTP on Mac OSX Leopard. It’s quirky and doesn’t always preserve tree structures when I try to move directories, so I often have to move files over one at a time. This is a messy process and produced errors for me when I installed the PHP4 extension, which has complex directory structure. Yet another reason to upgrade to PHP5…
  • Create a directory on your server that is devoted to Facebook projects.
  • Download the client library and footprints [test app, requires database] example. You should have three folders: client, footprints, php4client
  • If you’re using PHP4, download the PHP4 simplexml extension
  • Copy the PHP4 extension folder you’ve downloaded (titled simplexml44-0_4_4) and paste it so it is nested INSIDE the folder-directory called “php4client.” Do not change the name of the extension folder.ftp shot
  • Use FTP to transfer the client, footprints and php4client folders to your facebook folder on your server and verify that the folder trees are accurately copied. I encountered weird situations where folders that were supposed to be on the same level ended up nested within one another.
  • Create a new folder for the test app at the same level as client, footprints, php4client
  • Generate a file called “index.php” from the sample code on this page. You’ll have to click the link at the bottom. Add your API key and secret into the code.

  • On the line that says to require once facebook.php, check the path for accuracy. In the case of how I did it, I had to set it to say require_once ‘../php4client/facebook.php’; so the system would know which facebook.php to look for (the old-school version) and also to know how to navigate the directory tree structure. If I’d had PHP5, the “php4client” would have been “client” instead in the path.
  • Save the index.php file you’ve been working on and use FTP to upload into the test app directory that you have created.
  • Go the the FB developers page and EDIT SETTINGS for the app.
  • Set the “callback URL” to the directory where index.php is located. (The system will automatically look for index.php) — use the whole URL, including your domain.
  • Set the canvas URL to the URL of your app. This is the directory name, be it “scrabulous” or whatever. Just type one word in the space, it’s pretty obvious what you’ll need to do. Your app URL will then become http://apps.facebook.com/%5Byourcanvasurlhere%5D
  • Visit the URL that you’ve created and see if it works. It should. If not, check your files, tree structure, code, PHP version, file names and server settings. It took me a long time to get this working.

Hopefully that helps demystify the process a little, or adds more questions than answers. But this worked for me and hopefully it will work for you.

The next lesson, once I get things figured out, will detail how to create databases and build a simple database-based app. Or else I’ll go over basic coding techniques and modifications to the above app. We’ll see how the tech works out.

Advertisements




What I’m working on programmingwise

5 05 2008

Outputting MySQL records using AJAX to update the display without reloading the whole page.Adding records to the MySQL database using a simple form and some PHP.

You might hear me talking about “my sequel” and other things. No, I’m not working on yet ANOTHER sequel to Harry & Kumar go to White Castle. So relax. What I’m talking about is MySQL, an open-source database Thingy that I am toying with. It is something that comes with the territory of my GoDaddy hosting account, so I thought I’d play with it. This entails learning the PHP scripting language to access it and manipulate it via the outside world and the Internetwebs, and in turn includes stirring in many other technologies. Bundled together, they are referred to as Ajax. Javascript, XML, and more.

Isn’t it geeky?

The screencaps above show you the program I’m working on. Simple stuff. Add a record, display it. The cool thing is this is pretty much how other software, such as WordPress, etc., works at its core. You make a new record in a database every time you plug in a blog entry, such as I’m about to do now.

My dream, my goal, only not quite, is to devise (on my own and by Frankensteining a number of techniques) a streamlined interface for information sharing that I can play with. I haven’t yet figured out what it will be, but I hope it’s something that I can employ to automate certain tasks, as well as use at home and in my personal life to display information simply and elegantly. I don’t know how far I’ll get on this project, but it’s a fun way to learn, regardless.