2010-01-03 101 views
3

我正嘗試使用Facebook連接在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!'; 
} 

這一切工作正常,但返回的事項標識始終是不同的事件一樣。當我在我的Facebook帳戶中查看時,該活動已成功添加,但該ID完全不同。任何想法我可能做錯了什麼?

我想通了這個問題。這是因爲我的數據庫字段被設置爲int,不幸的是,Facebook的ID太長了。

回答

3

我想通了這個問題。這是因爲我的數據庫字段被設置爲int,不幸的是,Facebook的ID太長了。我只需要改變字段類型。

0

相反的:

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

我想你想:

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

那麼,$ fapi實際上是 $ fapi = $ facebook-> api_client; – Dhana 2010-01-03 20:02:51

+0

無論如何都要試試看,只是爲了看到 – 2010-01-03 20:03:37

+0

它仍然會返回與該更改相同的ID – Dhana 2010-01-03 20:08:54

0

的參數events_create()需要是JSON編碼的字符串。更改此:

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

這樣:

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

嘗試過,事件獲得成功添加,但eventid仍然相同 – Dhana 2010-01-03 20:42:44