Graph API - 由所有者/创建者获取事件 [英] Graph API - Get events by owner/creator

查看:118
本文介绍了Graph API - 由所有者/创建者获取事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Facebook Graph API可以获取单个配置文件创建的所有事件的列表吗?我们的客户端创建了一系列事件,我们想要列出所有的事件。我说他们只需要确保自己参加这个活动,因为我可以很容易的拉出一个profileId参加的活动列表,但是如果有另一种方式,我很好奇。也许是FQL查询?他们希望在主键上需要查询。那么FQL查询会是什么样的,如果这样做呢?

Is there a way with the Facebook Graph API to get a list of all events created by a single profile? Our client creates a bunch of events and we want to pull a list of them all. I said that they would just have to make sure they set themselves to be attending the event, because then I can easily pull the list of events that profileId is attending, but I'm curious if there's another way. Maybe an FQL query? They look to require a query on the primary key though. And what would that FQL query look like if that's the way to do it??

推荐答案

我基本上使用了$ c> FQL @jhchen提供。但是,花了大约6个小时来弄清楚如何使用这个 FQL 。所以我想,我会为你提供一个工作的脚本。这不完美,所以如果发现错误,请更新。

I basically used the FQL that @jhchen provided. However, it took me about 6 hours to figure out how to use that FQL. So I figured, I would provide you a working script. It's not perfect so please update it if you find a bug.


  1. 下载 Facebook的PHP SDK

  2. 添加 YOUR_APP_ID

  3. 添加 YOUR_APP_SECRET

  4. 添加 PAGE_ID

  5. 您认为合适的 FQL 语句。 FQL文档

  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

除此之外你应该很好去。此外,我将默认时区设置为 America / Los_Angeles 。这可能会导致一些人的问题,如果任何人有更好的方式来处理时区,请让我知道。

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

PHP代码

<?php
require_once("php/facebook.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;
}

这篇关于Graph API - 由所有者/创建者获取事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆