如何使用Graph API以编程方式将事件添加到页面?

时间:2011-02-07 19:41:46

标签: facebook events http facebook-graph-api access-token

是否可以使用Facebook Graph API以编程方式将事件添加到页面? 如果是,应该发出什么HTTP请求?

例如,Startup Weekend有events on its Facebook page。 可以使用Graph API Event object添加这些事件吗?

1 个答案:

答案 0 :(得分:9)

<强>更新

在v2.0 +中使用API​​创建事件不再可能。检查:https://developers.facebook.com/docs/apps/changelog#v2_0


是的,这是可能的。

Permissions:

  1. create_event
  2. manage_pages
  3. 首先,您通过以下方式获取页面ID及其访问令牌:

    $facebook->api("/me/accounts");
    

    结果将类似于:

    Array
    (
        [data] => Array
            (
                [0] => Array
                    (
                        [name] => Page Name
                        [category] => Website
                        [id] => XXXXXX
                        [access_token] => XXXXX
                    )
    
                [1] => Array
                    (
                        [name] => Page Name 2
                        [category] => Company
                        [id] => XXXXXXX
                        [access_token] => XXXXXXXX
                    )
            )
    
    )
    

    更新:要检索网页的access_token,您现在可以直接调用page对象:

    $page_info = $facebook->api("/PAGE_ID?fields=access_token");
    

    如果成功通话,则可以访问访问令牌:$page_info['access_token']

    现在您获得了网页ID和访问令牌,并使用events连接:

    $nextWeek = time() + (7 * 24 * 60 * 60);
    $event_param = array(
        "access_token" => "XXXXXXXX",
        "name" => "My Page Event",
        "start_time" => $nextWeek,
        "location" => "Beirut"
    );
    $event_id = $facebook->api("/PAGE_ID/events", "POST", $event_param);
    

    你完成了! : - )