Creating a Facebook Canvas Application

I’ve been developing Facebook apps for years, some of which you can see on In this time, I’ve seen many changes to the Facebook platform and have learned a few things along the way. Now, I thought I would share my knowledge of making Facebook apps on this blog. I’ll try to show examples […]

Authentication for Canvas Applications

Now that we’ve covered the setting up an app, we’re ready for the first step in creating a real application, which is authenticating users.  To do this, we need to check to see if a user has already authenticated our app and prompt them to do so if they haven’t. (Note, I use authorize and […]

Permissions and Basic Graph API Calls

Because of the way Facebook apps used to work, many canvas apps do not have an “authorize” link as in the previous example and simply direct users to the authorization dialog. Some apps have a landing page, which doesn’t require authorization and other pages that do. We’ll implement methods to allow us to accomplish this. […]

Facebook Friends List and Paging

Friends List Facebook is all about friends so one of the basic things most apps need is a list of a user’s friends. This is easy to get with the graph API using  the object “me/friends”.  No additional permissions are required for this. Let’s start by creating a page called /demo/myfriends.php and look at the […]

Friend Locations and Batch API

Now that we have a list of all friends ids, we can get more information about them. A problem is that a user can have 5000 friends, and hitting the api separately for each one would consume a lot of resources. Fortunately, Facebook has a way to make batch requests. Batch Requests To make a […]

Publishing to the Facebook Feed

So far we have used to graph API to get data from Facebook, but for an app to be useful, it also has to publish to Facebook. This can be done in several ways. We’ll cover posting using the graph API and directing a user to a feed dialog URL. We’ll skip using the FBJS […]

Creating a Sqlite Cache

Some of the things we’ve done like getting a list of friends and getting their location have required a lot of API calls. It doesn’t make sense to repeatedly make requests like this to the Facebook API, so we’ll create a basic caching system. We’ll use Sqlite which should be part of the latest version […]

Caching the Facebook API and cURL

Now that we’ve set up a caching system, we can use it to cache cURL requests and Facebook API calls. cURL Object First we’ll create a simple object /lib/CurlClient.php to make curl requests and use the Cache object previously created. class CurlClient {     private $useragent = “MyCurlClient”; // set this to your own user […]

Deauthorize Callbacks and User Database

Any real app is going to need a database to store information about users and whatever is relevant to the app. We’ll add a database to our demo to track when a user first authorized the app, when the user does something significant, and when the deauthorizes the app. User Table We’ll set up a […]

Foundations of a Facebook App Framework

Now that we have several classes developed, it’s time to put them together in a simple framework that will help us quickly and easily develop Facebook apps. Directory Structure All our shared classes are in a directory called lib. For the sake of making previous examples cleaner this was kept in the www along with […]

Setting the Facebook Canvas Height

When we set up our demo canvas app, we took a shortcut by entering a large number for the height. A real app should have an iframe that adjust to fit the content. Luckily this is easy to do with Facebook’s JavaScript Library called FBJS. We first have to include the library right after the […]

Long-Lived Facebook Tokens

When Facebook passes a signed_request to a canvas app, the token is valid for two hours. This is more than enough for any canvas page, but if we want to do something with a cron after the  user has left the app, we need a long-lived token. There are two ways we can get this: […]

Facebook App in a Day: Birthday Greetings

Facebook no longer allows posting to friends, so this app is not viable. Now that I have a framework, my personal challenge is to create an app in a day using it. One of the rituals on Facebook is to post a message to friends on their birthdays. I think an app that let’s people […]

Facebook App Test Users

Now that we have a complete app set up, we need to test it, but we don’t want to post all sorts of birthday greetings to friends. Luckily Facebook has a system to create test users. Just go to your apps in the developer admin, click “edit settings” for your app then “roles” from the […]

Website with Facebook Login

Many websites are using Facebook login. This gives users the convenience of having a single account across multiple sites and allows the sites to access the social graph and API. Our canvas apps are essentially websites in iframes, so it shouldn’t be too difficult to turn them into websites of their own. The same framework […]

Mobile Web Facebook Apps

People are increasingly using Facebook on mobile devices. Unless an app has a mobile web version, it will be invisible to these people. Even the posts it makes will not be displayed on mobile devices. Since we now have a framework to create websites with Facebook login, it will be relatively easy to create mobile […]

Authenticated Referrals for Facebook Apps

Facebook no longer supports authenticated referrals, but this code will still work for App Center pages and links from bookmarks, etc. Have you ever seen a link in your Facebook feed that says a friend just read an article on a website, and then when you click that link it asks you to Facebook authenticate […]

Keeping Up with Facebook Changes

One of the difficulties of developing Facebook apps is that Facebook is always changing the platform, both technically and legalistically. You should follow their blog to make sure that you are always up to date. Recently, they’ve made some changes which require revisions to the framework we’ve created. API Can’t Post to Friends The API […]

Setting Up an Amazon EC2 LAMP Stack

Amazon Web Services have become the platform of choice for many startups. They are robust and economical as well as being able to scale quickly. Most solo developers, like me, aren’t server administrators and it can take a while to piece everything together, so I thought I’d share how I do it in case it […]

Updating Framework for Amazon EC2

Now that we have a fancy new Amazon EC2 server, we need to update some things in the framework to make it work. Server Variables The server doesn’t support $_SERVER[‘SCRIPT_URI’] so we’ll need to make some changes in appframework.php. On line 118: $success_uri = $_SERVER[‘SCRIPT_URI’].”?”.$_SERVER[‘QUERY_STRING’]; changed to $success_uri = ($_SERVER[‘HTTPS’] == “on”) ? “https://” : […]