No revolutions here but since Facebook’s documentation always lacks a bit behind because they move too fast, it might be useful to some of you.
First things to know is that pages are owned by users not applications and you can only interact with facebook as an application on the behalf of a user. First thing first, you need to create an application.
To act on a Page from an application, the administrator of a Page your application want to administrate must give you the permission to manage his pages. This permission is called, no surprises here: manage_pages
.
Once the permission is granted, an access_token can be retrieved from https://graph.facebook.com/me/accounts
and used from the application to interact with the page.
Nowadays Facebook applications should be made using mostly the JavaScript SDK to login, logout and so forth. That said, ours gonna be static only as we don’t need more.
Okay, now you have an application and a page with its access_token. Let’s have fun with the Graph API. Frankly, there isn’t much I can say against the Graph API. It’s a nice example of REST API build upon a very complex data schema.
Let’s submit something.
<?php $fb = new Facebook(array( appId => null, secret => null )); $message = 'Hello World!'; $access_token = /* token for the page */; $fb->api( '/pageNameOrId/feed', 'POST', compact('access_token', 'message') );
This a simple message, you can make it way more complex. The message will appear as being posted by your application, so pick a cool name.