Ejemplo n.º 1
0
 /**
  * Creates an event on Facebook.
  *
  * @param string $title Title of the event.
  * @param int $start Epoch timestamp for the event start.
  * @param int $end Epoch timestamp for the event end.
  * @param string $location Location of the event.
  * @param string $description Description of the event.
  * @param string $picture Local path (no URL) of the picture for the event.
  *
  * @return array Result set of the Facebook API call.
  * @todo Standardise the result sets of connection API calls.
  */
 public function createEvent($objectId, $title, $start, $end, $location, $description, $picture = null)
 {
     // Privacy types: OPEN, CLOSED, SECRET
     $start = is_numeric($start) ? date("c", $start) : $start;
     $end = is_numeric($end) ? date("c", $end) : $end;
     $attachment = array("privacy_type" => "OPEN", "name" => $title, "host" => "Me", "start_time" => $start, "end_time" => $end, "location" => $location, "description" => $description);
     if ($picture) {
         $attachment[basename($picture)] = "@" . realpath($picture);
         $this->api()->setFileUploadSupport(true);
     }
     try {
         // TODO: support pages (page Id instead of "me")
         $rs = $this->api()->api('me/events', 'post', $attachment);
     } catch (Exception $e) {
         Log::error("Exception: {$e}");
     } catch (FacebookApiException $e) {
         Log::debug("FacebookApiException {$e}, " . print_r($attachment, true) . print_r($this, true));
         return null;
     }
     $publication = new Publication();
     $publication->setObjectId($objectId);
     $publication->setConnectionId($this->externalId);
     $publication->setBody(serialize($attachment));
     $publication->setResponse(serialize($rs));
     if (isset($rs['id'])) {
         list($uid, $postId) = explode("_", $rs['id']);
         $publication->setExternalId($postId);
     } else {
         $result->error = $rs;
         Log::debug("error: {$result->error}");
     }
     $publication->save();
     return $rs;
     // TODO: invites
     // $fb->api( array(
     //   'method' => 'events.invite',
     //   'eid' => $event_id,
     //   'uids' => $id_array,
     //   'personal_message' => $message,
     // ) );
 }