如何获取 Facebook 应用程序创建的所有事件?

发布于 2024-10-13 02:53:33 字数 302 浏览 2 评论 0原文

如何使用 Graph API 获取 Facebook 应用程序创建的所有事件?我尝试这样做,

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

但没有成功。

How can I get all events 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

悟红尘 2024-10-20 02:53:33
  1. 下载 Facebooks PHP SDK
  2. 添加 YOUR_APP_ID
  3. 添加 YOUR_APP_SECRET
  4. 添加 PAGE_ID
  5. 如您所见,对 FQL 语句进行更改合身。 FQL 文档

除此之外,您应该可以开始了。另外,我将默认时区设置为 America/Los_Angeles。这可能会在以后引起问题,如果有人有更好的方法来处理它,请告诉我。

PHP 代码:

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;
}
  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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文