是否可以使用Facebook Graph API以编程方式将事件添加到页面? 如果是,应该发出什么HTTP请求?
例如,Startup Weekend有events on its Facebook page。 可以使用Graph API Event object添加这些事件吗?
答案 0 :(得分:9)
<强>更新强>
在v2.0 +中使用API创建事件不再可能。检查:https://developers.facebook.com/docs/apps/changelog#v2_0
是的,这是可能的。
Permissions:
create_event
manage_pages
首先,您通过以下方式获取页面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);
你完成了! : - )