Hooks
Last modified: November 7, 2009 - 00:13
This documentation is for 5.x version and may be out of date. Upgrade to the latest version.
Definition
hook_fb($fb, $fb_app, $op, $return, $data)
Description
Enables custom code to be executed when various operations are carried out by the Drupal for Facebook module
Parameters
- $fb: Facebook API object
- $fb_app: a drupal node representing the current Facebook application
- $op: the operation being carried out by the Drupal for Facebook module
- $return: placeholder for returned data
- $data: additional data relevant to the current operation
Operations
- FB_OP_INITIALIZE: Start a FB callback
- FB_OP_POST_INIT: Another chance to start FB callback
- FB_OP_EXIT: End an FB callback
- FB_OP_GET_FBU: Query the local user's FB account
- FB_OP_GET_APP: Query which app a FB callback addresses
- FB_OP_GET_INFINITE_SESSION: Query infinite session data
- FB_OP_PRE_USER: Before account creation, fb_user.module
- FB_OP_POST_USER: After account creation, fb_user.module
Example
When a user adds the application, add a post to their wall so that their friends know they have added it
This depends on
- the Facebook application being configured to require a Drupal account
- a Facebook template being registered with the text of the message to appear in the user feed
In this example, the user's gender is used to add some personalisation to the message:
[name] has added the application to [his/her/their] profile
<?php
function mymodule_fb($fb, $fb_app, $op, $return, $data) {
if($op == FB_OP_POST_USER) {
$user_details=$fb->api_client->users_getInfo($fb->user, array('sex'));
$template_bundle_id = 12345;
if($template_bundle_id) {
switch($user_details[0]['sex']) {
case 'male':
$gender = 'his';
break;
case 'female':
$gender = 'her';
break;
default:
$gender = 'their';
}
$tokens = array(
'gender' => $gender,
);
$fb->api_client->feed_publishUserAction($template_bundle_id, json_encode($tokens), array(), '');
}
}
}
?>Note that the same functionality can be achieved using the modules Actions, Drupal for Facebook Actions, Drupal for Facebook Feeds.
