Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook create event

Tags:

php

facebook

I am trying to create events on Facebook using Facebook connect. So far, the

$appapikey = 'my key here';

$facebook = new Facebook($appapikey, 'my secret here');
$user = $facebook->require_login();
$fapi = $facebook->api_client;

if(!$facebook->api_client->users_hasAppPermission('create_event')){
    echo'<script type="text/javascript">window.open("http://www.facebook.com/authorize.php?api_key='.$appapikey.'&v=1.0&ext_perm=create_event", "Permission");</script>';
    echo'<meta http-equiv="refresh" content="0; URL=javascript:history.back();">';
    exit;
}

$event_info = array();
$event_info['name'] = $_POST['name'];
$event_info['category'] = 8;
$event_info['subcategory'] = 36;
$event_info['host'] = 'Me';
$event_info['location'] = $_POST['location'];
$event_info['email'] = $_POST['email'];
$event_info['phone'] = $_POST['phone'];
$event_info['description'] = $_POST['description'];
$event_info['city'] = $_POST['city'];
if($_POST['start_time_ampm'] == 'PM'){
    $_POST['start_time_hour'] = $_POST['start_time_hour'] + 12;
}
if($_POST['end_time_ampm'] == 'PM'){
    $_POST['end_time_hour'] = $_POST['end_time_hour'] + 12;
}

$event_info['start_time'] = mktime($_POST['start_time_hour'],$_POST['start_time_min'],00,$_POST['start_time_month'],$_POST['start_time_day'],$_POST['start_time_year']); //Converts time to UTC
$event_info['end_time'] = mktime($_POST['end_time_hour'],$_POST['end_time_min'],00,$_POST['end_time_month'],$_POST['end_time_day'],$_POST['end_time_year']);



try{
    echo json_encode($_POST);
    $event_id = $fapi->events_create($event_info);
    $sql = "INSERT into events (EventId) values('$event_id')";
    $result = mysql_query($sql) or die("can't select events<br>$sql".mysql_error());
    echo 'Event Created!';
}

This all works fine, but the event_id returned is always the same for different events. When I look in my Facebook account, the event was successfully added, but the id there is totally different. Any idea what I may be doing wrong?

I figured out this issue. It was because my database field was set to an int and unfortunately, the Facebook id's were too long.

like image 986
DLS Avatar asked Apr 08 '26 15:04

DLS


1 Answers

I figured out this issue. It was because my database field was set to an int and unfortunately, the Facebook id's were too long. I just had to change the field type.

like image 150
DLS Avatar answered Apr 11 '26 04:04

DLS



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!