Php Facebook创建活动

Php Facebook创建活动,php,facebook,Php,Facebook,我正在尝试使用Facebook connect在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_hasAppPe

我正在尝试使用Facebook connect在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!';
}
$appapikey='my key here';
$facebook=newfacebook($appapikey,‘我的秘密在这里’);
$user=$facebook->require_login();
$fapi=$facebook->api\U客户端;
如果(!$facebook->api\u客户端->用户\u拥有AppPermission('create\u event')){
“回声”窗口。打开(“http://www.facebook.com/authorize.php?api_key=“.$appapikey.&v=1.0&ext_perm=create_event”、“Permission”);”;
回声';
出口
}
$event_info=array();
$event_info['name']=$_POST['name'];
$event_info['category']=8;
$event_info['子类别]]=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']=$u POST['city'];
如果($\u POST['start\u time\u ampm']='PM'){
$\u POST['start\u time\u hour']=$\u POST['start\u time\u hour']+12;
}
如果($\u POST['end\u time\u ampm']='PM'){
$\u POST['end\u time\u hour']=$\u POST['end\u time\u 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'])//将时间转换为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']);
试一试{
echo json_编码($_POST);
$event\u id=$fapi->events\u create($event\u info);
$sql=“插入事件(EventId)值(“$event\u id”)”;
$result=mysql\u query($sql)或die(“无法选择事件”
$sql.mysql\u error()); echo“已创建事件!”; }
这一切都很好,但对于不同的事件,返回的事件id始终相同。当我查看我的Facebook帐户时,事件被成功添加,但那里的id完全不同。知道我做错了什么吗

我发现了这个问题。这是因为我的数据库字段设置为int,不幸的是,Facebook id太长。

而不是:

$event_id = $fapi->events_create($event_info);
我想你想要:

$event_id = $facebook->api_client->events_create($event_info);

events\u create()
的参数必须是JSON编码的字符串。更改此项:

$event_id = $fapi->events_create($event_info);
为此:

$event_id = $fapi->events_create(json_encode($event_info));

我解决了这个问题。这是因为我的数据库字段设置为int,不幸的是,Facebook id太长了。我只需要更改字段类型。

嗯,$fapi实际上是$fapi=$facebook->api\u客户端;它仍然返回相同的id和该更改。同样,事件被成功添加,但eventid仍然相同