您好我使用以下代码,以便根据提供的网址从Facebook检索事件信息。
代码是这样的:
function importEvent($url)
{
$facebook = new Facebook(array(
'appId' => 'someAppId',
'secret' => 'someSecret',
'cookie' => true, // enable optional cookie support
));
if(checkLogin()==true)
{
//get rid of hash if exists
$hash = explode('#',$url);
if(!empty($hash[1]))
$array = parse_url($hash[1]);
else
$array = parse_url($hash[0]);
parse_str($array['query'],$output);
$eid = $output['eid'];
if(empty($eid))//new url think http://www.facebook.com/events/2323423423423/
{
$url = str_replace('http://www.facebook.com/events/','',$url);
$url = str_replace('https://www.facebook.com/events/','',$url);
$hash = explode('/?',$url);
if(!empty($hash[1]))
$url = $hash[0];
$eid = str_replace('?','',$url);
$eid = str_replace('/','',$url);
//print_r($eid);
}
//Calling users.getinfo legacy api call example
try{
$param = array(
'method' => 'events.get',
'eids' => $eid,
'access_token' => $_SESSION['access_token']
);
$events = $facebook->api($param);
}
catch(Exception $o){
error_log($o);
echo $o;
}
print_r($events);
return $events;
}
}
我得到的输出是:
Array
(
[0] => Array
(
[eid] => 410474065693887
[name] => Sunday Night Fever Vol.4 Disco Special @Legacy Rock Area
[pic_small] => http://profile.ak.fbcdn.net/hprofile-ak-snc6/276862_410474065693887_714884848_t.jpg
[pic_big] => http://profile.ak.fbcdn.net/hprofile-ak-snc6/276862_410474065693887_714884848_n.jpg
[pic] => http://profile.ak.fbcdn.net/hprofile-ak-snc6/276862_410474065693887_714884848_s.jpg
[pic_square] => http://profile.ak.fbcdn.net/hprofile-ak-snc6/276862_410474065693887_714884848_q.jpg
[has_profile_pic] => 1
[host] => Legacy Rock Area
[version] => 2
[description] => Αφου μας το ζητησατε "παρτε" το..!!!
Μετα το τελευταιο απιστευτο killer Disco Party εχουμε την ευκαιρια να κανουμε προθερμανση για τον Super Αποκριατικο Φεβρουαριο που θα ακολουθησει στο Legacy Rock Area μεμια βραδυα γεματη Disco,Dance,Pop και οπου μας βγαλει...!!
Κυριακη 20 Ιανουαριου λοιπον..Sunday Night Fever Disco Special!!!
That night the DJ saves our lives...!!!
[start_time] => 2013-01-20
[end_time] =>
[timezone] =>
[is_date_only] => 1
[creator] => 1732432279
[update_time] => 1357737066
[location] => Legacy Rock Area
[hide_guest_list] =>
[can_invite_friends] =>
[privacy] => OPEN
[venue] => Array
(
[id] => 244479685665743
)
[all_members_count] => 7175
[attending_count] => 74
[unsure_count] => 144
[declined_count] => 509
[not_replied_count] => 6957
)
)
然而,在api文档中,它提到该地点包含以下内容:
此活动的位置 通用access_token,user_events或friends_events 包含以下一个或多个字段的对象:id,street,city,state,zip,country,latitude和longitude fields。
但我得到的只是场地ID。
我无法找到有关如何检索场地的lat + lng的特定信息,我认为如果我没有弄错的话,这段代码是可以的。
我是否需要仅针对场地信息执行另一个查询,如果可以,请提供任何参考或代码示例?或者这段代码是否有办法返回lat + lng,所以我不必为1个事件做2个查询?
答案 0 :(得分:0)
经过一些研究后,我发现这可以用fql.multiquery做,现在看起来效果很好。这是源代码。
function importEventFQL($url)
{
$facebook = new Facebook(array(
'appId' => 'someApddID',
'secret' => 'someSecret',
'cookie' => true, // enable optional cookie support
));
if(checkLogin()==true)
{
list($url_static,$url_URI) = explode('/events',$url);
$url_URI = ltrim($url_URI,'/');
list($eid, $trash) = explode('/?',$url_URI);
$fql = '{';
$fql .= '"event_info":"SELECT name, description, pic_small, pic_big, eid, venue, location, start_time, end_time, host from event WHERE eid=\'' . $eid . '\'",';
$fql .= '"event_venue":"SELECT name, username, page_id, location FROM page WHERE page_id IN (SELECT venue.id FROM #event_info)"';
$fql .= '}';
$param = array(
'method' => 'fql.multiquery',
'queries' => $fql,
'callback' => ''
);
$result = $facebook->api($param);
print_r($result);
}
}
答案 1 :(得分:0)
如果您只想让FQL执行此操作:
{
"events" : "SELECT privacy, name, description, start_time, venue.id, pic_cover FROM event WHERE eid IN (SELECT eid FROM event_member WHERE uid = me())",
"venues" : "SELECT latitude, longitude, name, page_id FROM place WHERE page_id IN (SELECT venue.id FROM #events)"
}