开发者

How can I get all events created by an Facebook application?

How can I get all event开发者_运维知识库s created by a Facebook application using the Graph API? I tried doing

$appevents = $facebook->api('/**applicationid**/events',
  'get', array("fields"=>"id, name, start_time, updated_time"));

but it did not work.


  1. Download Facebooks PHP SDK
  2. Add YOUR_APP_ID
  3. Add YOUR_APP_SECRET
  4. Add PAGE_ID
  5. Make changes to the FQL statement as you see fit. FQL Documentation

Other than that you should be good to go. Also, I set the default timezone to America/Los_Angeles. This will probably cause problems later, if anyone has a better way to handle it please let me know.

PHP Code:

date_default_timezone_set('America/Los_Angeles');

function display_events()
{
    $app_id = 'YOUR_APP_ID';
    $secret = 'YOUR_APP_SECRET';
    $page_id = 'PAGE_ID';

    $config = array();
    $config['appId'] = $app_id;
    $config['secret'] = $secret;
    $config['fileUpload'] = false; // optional

    $facebook = new Facebook($config);

    $fql = 'SELECT 
                eid, 
                name, 
                pic_square, 
                creator,
                start_time,
                end_time
            FROM event 
            WHERE eid IN 
                (SELECT eid 
                    FROM event_member 
                    WHERE uid='.$page_id.'
                ) 
            AND end_time >= ' . mktime() . '
            ORDER BY start_time ASC
    ';

    $ret_obj = $facebook->api(array(
        'method' => 'fql.query',
        'query' => $fql,
    ));

    $html = '';                            
    foreach($ret_obj as $key)
    {
        $facebook_url = 'https://www.facebook.com/event.php?eid=' . $key['eid'];

        $start_time = date('M j, Y \a\t g:i A', $key['start_time']);
        $end_time = date('M j, Y \a\t g:i A', $key['end_time']);

        $html .= '
            <div class="event">
                <a href="'.$facebook_url.'">
                    <img src="'.$key['pic_square'].'" />
                </a>
                <span>
                    <a href="'.$facebook_url.'">
                        <h2>'.$key['name'].'</h2>
                    </a>
                    <p class="time">'.$start_time.'</p>
                    <p class="time">'.$end_time.'</p>
                </span>
            </div>
        ';
    }

    echo $html;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜