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

Can I programmatically add an event to a page using the Facebook API? If so, what HTTP request should be made?

For example, Startup Weekend has events on its Facebook page . Can these events be added using the Graph API Event Object ?

+4
source share
1 answer

UPDATE

Creating an event using the API is no longer possible in version 2.0. Check out: https://developers.facebook.com/docs/apps/changelog#v2_0


Yes it is possible.

Permissions:

  • create_event
  • manage_pages

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

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

The result will be something like this:

 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 get the access_token page, you can now call the page object directly like this:

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

Access to the token on a successful call must be available: $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're done !:-)

+9
source

Source: https://habr.com/ru/post/1338762/


All Articles