0

您好,我使用以下代码根据提供的 url 从 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 字段。

但我得到的只是场地ID。

我找不到有关如何检索场地地点的 lat + lng 的特定信息,如果我没记错的话,我认为这段代码是可以的。

我是否需要仅针对场地信息执行另一个查询,如果需要,您能否提供任何参考或代码示例?或者有没有办法让这段代码也返回 lat + lng,所以我不必为 1 个事件进行 2 次查询?

4

2 回答 2

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);
    }   
}
于 2013-01-20T20:05:36.233 回答
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)"
}
于 2013-05-31T21:20:54.103 回答