Skip to content

Instantly share code, notes, and snippets.

@nazt
Created August 29, 2011 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nazt/1178154 to your computer and use it in GitHub Desktop.
Save nazt/1178154 to your computer and use it in GitHub Desktop.
page.event.create.attach.image.php
<?php
/**
* Implementation of hook_nodeapi
*/
function hps_the_hook_nodeapi (&$node, $op, $a3 = NULL, $a4 = NULL) {
if ($node->type == 'event') {
if ($op == 'insert') {
dpm($node);
//require_once(drupal_get_path('module', 'hps_the_hook') . '/lib/facebook-php-sdk/src/facebook.php');
$facebook = new Facebook(array(
'appId' => '193560340711521',
'secret' => 'secret',
'fileUpload' => true,
));
$page_id = "161330440592966";
$location = $node->field_location[0]['value'];
$from_date = $node->field_date[0]['value'];
$to_date = $node->field_date[0]['value2'];
$image_path = $node->field_image[0]['filepath'];
$event_param = array(
"access_token" => 'access_token',
"name" => $node->title,
"start_time" => strtotime($from_date),
"end_time" => strtotime($to_date),
"location" => $location,
"page_id" => $page_id,
"picture" => "@".realpath($image_path),
"source" => "@".realpath($image_path),
);
$facebook->setFileUploadSupport(true);
try {
dpm($event_param);
$event_id = $facebook->api("/161330440592966/events", "POST", $event_param);
dpm($event_id);
}
catch (Exception $ex) {
dpm($ex);
}
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment