我正在尝试使用Facebook连接在Facebook上创建活动。到目前为止,
$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!';
}
这一切都运行正常,但返回的event_id对于不同的事件始终是相同的。当我查看我的Facebook帐户时,该活动已成功添加,但其中的ID完全不同。知道我可能做错了吗?
我发现了这个问题。这是因为我的数据库字段设置为int,不幸的是,Facebook ID太长了。
答案 0 :(得分:3)
我想出了这个问题。这是因为我的数据库字段设置为int,不幸的是,Facebook id太长了。我只需要更改字段类型。
答案 1 :(得分:0)
而不是:
$event_id = $fapi->events_create($event_info);
我想你想要:
$event_id = $facebook->api_client->events_create($event_info);
答案 2 :(得分:0)
events_create()
的参数需要是JSON编码的字符串。改变这个:
$event_id = $fapi->events_create($event_info);
到此:
$event_id = $fapi->events_create(json_encode($event_info));