Pawka
Pawka

Reputation: 2576

Creating Facebook event for specific page with FB Graph API

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]
);

Upvotes: 8

Views: 9620

Answers (4)

Daniel
Daniel

Reputation: 1531

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:

$page = $fbApi->api('/'.<page_id>,'GET',array('fields'=> 'access_token'));
$fbApi->setAccessToken($page['access_token']);

Upvotes: 0

Matias Paterlini
Matias Paterlini

Reputation: 11

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.

Upvotes: 1

Alastair
Alastair

Reputation: 6114

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.

Upvotes: 0

Julio Santos
Julio Santos

Reputation: 3895

«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?

Upvotes: 3

Related Questions