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.

Advertisement




Getting to know the Mac a little better…

18 04 2008

Out of Box ExperienceI’ve written a bit in other places about how I now use a MacBook Standard at home and how weird it is. It turns out that I enjoy this system a lot, but figuring out the Jobsian way of doing things (oh, OK, I drag the mouse and that scans through the photos. OK.) is creating a bit of a learning curve. There’s a few semantics, too, but I’m getting there. The system pretty much can be used at its most basic level with little or no extra learning effort, but mastering all the cute little media applications is a bit trickier.

Today I created a short sound clip of trumpet fanfare using GarageBand. It did a good job of approximating the musical notes (looking over them, they appeared to be for a far better song than I had done.) It’s cool that a computer would include a music-making app. It’s a nice touch. I hope people will learn how to use this software and make their own music instead of ripping copyrighted material. One must, however question the placement of the (only two) USB ports on the left side instead of the right, as well as the lack of anything beyond the most basic features and OH WELL these things aren’t that big of a deal. They’re part of the Mac experience. Coming off a gi-normous HP laptop with every bell and whistle imaginable, including a TV tuner, I’m going to have to, uh, make do with less. But… using the new computer and system has been an overall pleasant experience.

Now, I have a newer computer at work, too, and the process of migrating everything over created a couple rough spots, methinks, but it will be totally awesome once that’s resolved. Hey, no one said progress was easy.