I am trying to create a facebook event through a drupal content type "event". I call the hook_node_insert() to make a POST on Facebook.

function fb_event_create_node_insert($node){
    if ($node->type == "event"){
        // get field values submitted when a new content type "event" is saved
        $event_name = $node->field_event_name['und'][0]['value'];
        $event_start_date = $node->field_event_start_date['und'][0]['value'];

        // get facebook app_id & secret from fboauth variables
        $app_id = isset($app_id) ? $app_id : variable_get('fboauth_id', '');
        $app_secret = isset($app_secret) ? $app_secret : variable_get('fboauth_secret', '');

        // Get the link to get the facebook code (generated by fboauth module)
        $link = fboauth_action_link_properties('fb_event_create'); 

        print l(t('Create event'), $link['href'], array('query' => $link['query']));
        // output a link to https://www.facebook.com/dialog/oauth?client_id=CLIENT_ID&redirect_uri=http%3A//localhost%3A8888/cs/%3Fq%3Dfboauth%252Ffb_event_create&scope=manage_pages%2Ccreate_event
        // parameters are created by the fb_oauth action (scope=permission) and some settings of the module (client_id & redirect uri).


So I then have a link after having saved the node: when I click on it, it connects to facebook and gives me back a code as a parameter in my redirect uri (code has been modified):


It goes to the callback function defined earlier:

function fb_event_create_fboauth_actions() {
  $actions['fb_event_create'] = array(
    'title' => t('Create events on behalf of CS'),
    'callback' => 'fb_event_create_fboauth_action_event_create',
    'permissions' => array(
  return $actions;

And here is the callback function:

function fb_event_create_fboauth_action_event_create($app_id, $access_token) {
    $result = fboauth_graph_query("EVENT_ID/events", $access_token, array("name" => "test", "start_time" => "2013-04-04T19:00:00-0700"), 'POST');


Insert parameters to this callback function to be able to insert the $event_name and $event_start_date (that we find from the node_insert() hook above) to have the callback function like :

function fb_event_create_fboauth_action_event_create($app_id, $access_token, $name_fb_ev, $start_fb_ev) {
    $result = fboauth_graph_query("EVENT_ID/events", $access_token, array("name" => $name_fb_ev, "start_time" => $start_fb_ev), 'POST');

Thank you for any help guys!

1 Answer 1


I modified the fboauth_action_menu() to make it accept arguments:

function fboauth_menu() {
  $items['fboauth/%fboauth_action/%/%'] = array(
    'title' => 'Facebook connect',
    'page callback' => 'fboauth_action_page',
    'page arguments' => array(1, 'foo', 'foo'),
    'access callback' => TRUE,
    'file' => 'includes/fboauth.fboauth.inc',
    'type' => MENU_CALLBACK,
  return $items;

But then I had another problem with the function fboauth_action_page()it executed because it called the another function to get the access token because the two redirect_uri parameters were not the same between the code request to FB and the access token. All this, because the function to get the access token was not taking into account the parameters.

function fboauth_access_token($code, $action_name, $app_id = NULL, $app_secret = NULL) {
  $app_id = isset($app_id) ? $app_id : variable_get('fboauth_id', '');
  $app_secret = isset($app_secret) ? $app_secret : variable_get('fboauth_secret', '');

  // get the parameters from the redirect_uri by the drupal function arg() and includes them in the redirect_uri to get the access token.
  $query = array(
    'client_id' => $app_id,
    'client_secret' => $app_secret,
    'redirect_uri' => fboauth_action_url('fboauth/' . $action_name . "/" . arg(2) . "/" . arg(3) . "/", array('absolute' => TRUE, 'query' => !empty($_GET['destination']) ? array('destination' => $_GET['destination']) : array())),
    'code' => $code,

// rest of the function


Now, both redirect_uri are the same and my callback function defined earlier must also catch parameters from the url:

function fb_event_create_fboauth_action_event_create($app_id, $access_token) {
    $event_name = arg(2);
    $event_start_date = arg(3);

    $result = fboauth_graph_query("EVENT_ID/events", $access_token, array("name" => $event_name, "start_time" => $event_start_date), 'POST');


Hope this helps someone!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.