Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically add an event to a page using Graph API?

Is it possible to programmatically add an event to a page using Facebook Graph API? If yes, what HTTP request shall be made?

For example, Startup Weekend has events on its Facebook page. These events can be added using Graph API Event object?

like image 423
fjsj Avatar asked Feb 07 '11 19:02

fjsj


1 Answers

UPDATE

Creating event with the API is no longer possible in v2.0+. Check: https://developers.facebook.com/docs/apps/changelog#v2_0


Yes it's possible.

Permissions:

  1. create_event
  2. manage_pages

So first you get the page id and its access token, through:

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

The Result will be something like:

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

)

UPDATE: To retrieve the page's access_token you could now call the page object directly like:

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

The access token, if successful call, should be accessible: $page_info['access_token']

Now you get the Page ID and access token and use the events connection:

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

And you are done! :-)

like image 89
ifaour Avatar answered Nov 15 '22 03:11

ifaour