Support custom FB apps via Drupal - Need Callback/Hook API

dkruglyak - October 31, 2007 - 08:46
Project:Drupal for Facebook
Version:5.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:patch (code needs review)
Description

The current out-of-the-box limitation of the module is that it merely maps existing Drupal site content - via whatever menu paths Drupal provides to Facebook. This is great but not sufficient.

Really taking advantage of Facebook functionality requires significant coding to tap into the data provided by Facebook about friends, user info, etc. None of this functionality exists in Drupal and is mostly the domain of custom app development.

This custom development needs to occur in app-specific modules. However, D4F does not provide ways for wrapping / managing menu callbacks from Facebook apps. The information about custom app callbacks should be managed within the app content type - and invoke the right hooks. Basically we need a unified callback management & API.

I found the need to implement something like this while writing a custom FB app. I could try and package the code for contribution, but first would like to get a sense of how this could work best.

#1

Dave Cohen - October 31, 2007 - 16:54

There is a hook_fb already. Unfortunately, nothing is well documented, but a look through my code will show you how it works. hook_fb can make your module aware of various actions performed by the other facebook modules. It also allows you to replace the existing modules with your own improved implementations (hopefully that will not be necessary).

For example, if you write a module that implements hook_fb, you'll be called with $op == FB_OP_INITIALIZE at the beginning of any canvas page request. You'll also be called with $op == FB_OP_POST_INIT just a moment later, after other modules have initialized so for example the proper user will be known. You'll be called with $op == FB_OP_EXIT at the end of the canvas page request.

If there are ops missing from hook_fb, we can add them. Just let me know what you think is missing.

If, during a non-canvas page request your module needs to use the facebook API. Call fb_api_init($fb_app). It will return an instance of Facebook, the basic class provided by facebook's API.

There's really nothing preventing you from developing your own custom apps right now, except perhaps a lack of documentation.

#2

dkruglyak - October 31, 2007 - 17:41

Yes, I saw something about these hooks in the code, but was not clear what is that and how to use them.

However, more than just the hooks are needed. Say I am going to create an app with home at http://apps.facebook.com/app_name. Next I will need some app sub-pages / actions at locations like http://apps.facebook.com/app_name/arg1/arg2. What I need is to map app_name / arg1 / arg2 to my custom modules - in a way that would scale to many apps / actions.

RIght now I have custom code for this, but this ought to be a D4F function with callbacks managed in FB app content type.

#3

Dave Cohen - October 31, 2007 - 21:58

This is what the Drupal menu system is for. My goal is not to re-invent anything that Drupal already does.

#4

dkruglyak - November 1, 2007 - 01:44

Correct, however what is lacking is a link between a facebook app (node) and the callbacks it needs to function.

What is needed is a wrapper to help manage menus for custom FB modules to not reinvent the wheel every time.

#5

dkruglyak - November 11, 2007 - 01:04
Category:task» feature request
Status:active» patch (code needs review)

OK, I took a first crack at adding generation of menu callbacks to fb_navigation.module.

The patch adds a parameter to every app to optionally collect the base / root of the custom callbacks registered. The menu simply looks for the appropriate functions to generate app canvas, which can be implemented by custom modules.

I am using this now in my project. Please review and comment. I might post some examples later.

AttachmentSize
fb_navigation.module.patch3.6 KB

#6

dkruglyak - November 11, 2007 - 06:49

A little fix to argument processing ...

AttachmentSize
fb_navigation.module.patch3.7 KB

#7

Dave Cohen - November 11, 2007 - 09:25
Status:patch (code needs review)» active (needs more info)

I just don't get this. Maybe you can explain it better?

I look at your patch, and it seems like there's a level of indirection wrapped around the Drupal menu system, but nothing that the Drupal menu system does not already do. If your Drupal is installed at http://example.com/drupal, you can define http://example.com/drupal/my_app using the drupal menu hook. If you want, you can make http://example.com/drupal/my_app your apps callback URL, if your goal is to hide the rest of the site from the app.

The only thing that's clear to me is you've added a theme function for the canvas page. I'd rather see a way to set a custom theme per app, because the theme can have its own blocks and other settings. Rather than just a theme function for a canvas page.

If I'm just not getting it, please provide a concrete example of what the problem is and how this solves it.

#8

dkruglyak - November 11, 2007 - 19:31
Status:active (needs more info)» patch (code needs review)

Yes, I can explain it better.

This is something that any module can do, but that would be redundant. D4F should provide a simple service for generating default callbacks to reduce work for custom module developers and let them focus on custom logic, not re-inventing the wheel. Custom theming of canvas pages is also important. For custom apps it needs to be totally independent from regular Drupal theming.

I significantly rewrote and simplified the code, please take a look.

AttachmentSize
fb_navigation.module.patch2.84 KB
 
 

Drupal is a registered trademark of Dries Buytaert.