我创建了一个页面,您可以在其中查看公共页面中的事件
PHP代码
<?php
require 'src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'ID',
'secret' => 'SECRET',
'cookie' => true,
));
try{
$events=$facebook->api('/PAGE/events?access_token=TOKEN');
}catch (FacebookApiException $e){
error_log($e);
}
foreach ($events["data"] as $event){
// Time
$startTime=strtotime($event["start_time"]);
// Only Upcoming events
if ((time()-$startTime)<=60*60*24*1 || $startTime>time()){
echo '<li><a href="#" id="'.$event["id"].'" class="event_link">
<img class="ui-li-thumb" src="https://graph.facebook.com/'.$event["id"].'/picture?type=small" width="70px;" height="100%" />
<h3 class="ui-li-heading">'.$event['name'].'</h3>
</a></li>';
}
}
?>
工作正常我只是在列表
中得到最接近的事件如何更改输出顺序??(如果可能的话)。
答案 0 :(得分:2)
您可以使用usort:
//Sorts by name. Switch 'name' for other sorts.
//Switch 1 and -1 to reverse the sort.
usort($events["data"],function($a,$b){
if ($a['name'] == $b['name']) {
return 0;
}
return ($a['name'] < $b['name']) ? -1 : 1;
});
答案 1 :(得分:1)
你必须使用fql
。 FQL - Event
因此,在查询中,您可以使用ORDER BY
按顺序排序任何参数
例如:
从创建者= PAGE_ID和eid in的事件中选择eid(从event_member中选择eid,其中uid = PAGE_ID)ORDER BY start_time DESC
答案 2 :(得分:1)
<?php
require 'src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'ID',
'secret' => 'SECRET',
'cookie' => true,
));
$fql = "SELECT
name, pic, start_time
FROM
event
WHERE
eid IN ( SELECT eid FROM event_member WHERE uid = PAGE_ID )
AND
start_time >= now()
ORDER BY
start_time asc";
$param = array(
'method' => 'fql.query',
'query' => $fql,
'callback' => ''
);
$fqlResult = $facebook->api($param);
foreach( $fqlResult as $keys => $values ){
echo '<li><a href="#" id="'.$values["id"].'" class="event_link">
<img class="ui-li-thumb" src="'.$values['pic'].'" width="70px;" height="100%" />
<h3 class="ui-li-heading">'.$values['name'].'</h3>
</a></li>';
}
?>
解决!