使用 FB Graph API 为特定页面创建 Facebook 事件
我需要将 CMS 中的事件同步到 Facebook 特定页面。我正在尝试为我创建的页面创建一个事件,但仍然没有结果。我可以简单地创建与用户相关的事件,但与页面无关。代码使用 Facebook PHP-SDK。
$page_id = '31337';
$page = $facebook->api("/{$page_id}");
$event_data = array(
'name' => 'Event: ' . date("H:m:s"),
'start_time' => time() + 60*60,
'end_time' => time() + 60*60*2,
'owner' => $page
);
$post = $facebook->api("/{$page_id}/events", 'POST', $event_data);
执行此代码片段后,事件被创建,但正如我之前所说,它属于用户,尽管给定数据中的“所有者”是页面。我的应用程序具有manage_pages、create_event 和publish_stream 权限。我缺少什么?
解决方案
位于“旧 REST API” 文档我发现“new Graph API”仍然需要参数page_id。所以变量 $event_data 应该如下所示:
$event_data = array(
'name' => 'Event: ' . date("H:m:s"),
'start_time' => time() + 60*60,
'end_time' => time() + 60*60*2,
'page_id' => $page['id]
);
I need synchronize events from my CMS to Facebook specific page. I'm trying to create an event for my created page but still have no result. I can simply create events, related to user, but not to page. Code uses Facebook PHP-SDK.
$page_id = '31337';
$page = $facebook->api("/{$page_id}");
$event_data = array(
'name' => 'Event: ' . date("H:m:s"),
'start_time' => time() + 60*60,
'end_time' => time() + 60*60*2,
'owner' => $page
);
$post = $facebook->api("/{$page_id}/events", 'POST', $event_data);
After executing this snippet, event is created but as I've said before it belongs to user though 'owner' in given data is page. My app has manage_pages, create_event and publish_stream permissions. What I'm missing?
Solution
At "OLD REST API" documentation I have found that "new Graph API" still needs parameter page_id. So variable $event_data should be like below:
$event_data = array(
'name' => 'Event: ' . date("H:m:s"),
'start_time' => time() + 60*60,
'end_time' => time() + 60*60*2,
'page_id' => $page['id]
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
«如果应用程序具有该用户的活动会话密钥,则代表该用户创建一个事件;否则它会代表应用程序创建一个事件。» — 来源
这能回答您的问题吗?
«Creates an event on behalf of the user if the application has an active session key for that user; otherwise it creates an event on behalf of the application.» — Source
Does this answer your question?
您需要传递托管页面的访问令牌,您可以从 graph.facebook.com/me/account 获取该令牌(当然,传递您的访问令牌以获取您管理的粉丝页面列表)。您将看到每个粉丝页面的访问令牌列表,使用它们来创建活动或发布到您的粉丝页面。
You need to pass the access token of the managed page, which you can get from graph.facebook.com/me/account (of course passing your access token to get the list of fan pages you manace). You will see there a list of access tokens for each of your fan pages, use those to create events or post to your fanpage.
有趣的是——我的经历恰恰相反。我尝试使用 page_id 参数创建事件并收到权限错误。删除 page_id 并且工作正常。诀窍是使用应用程序访问令牌而不是用户一。
Interesting- my experience is exactly the opposite. I tried creating the event with the page_id parameter and got a Permissions Error. Removed the page_id and it worked fine. The trick was to use the application access token rather than user one.
在发帖之前将 access_token 设置为第一页。确保您的应用程序具有“manage_pages”权限才能正常工作。
像这样:
Set the access_token to the page one before making the post. Make sure you app has the "manage_pages" permission for this to work.
Like this: